Part Number Hot Search : 
LG122324 D40F120 B230006 AN470 XXXSP ACS401 035CT DTC11
Product Description
Full Text Search
 

To Download ST20-C1 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 1/205 ST20-C1 core instruction set reference manual 72-trn-274-01 july 1997
contents ? 2/205 contents 1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 1.1 ST20-C1 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 1.2 manual structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 2 notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 2.1 instruction listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 2.2 instruction definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . ..............8 2.3 operators used in the definitions . . . . . . . . . . . . . . . . . . . . . . . . .......11 2.4 data structures and constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 3 architecture . . . . . . . . ...........................................16 3.1 values . . . . . . . . . . . . . . ......................................16 3.2 memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .......18 3.3 registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20 3.4 instruction encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24 4 using ST20-C1 instructions ......................................30 4.1 manipulating the evaluation stack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30 4.2 loading and storing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31 4.3 expression evaluation . . . . . . . . . . ..............................33 4.4 arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35 4.5 forming addresses . . . . . . . . . . . . . . . . . .........................41 4.6 comparisons and jumps . . . ...................................43 4.7 evaluation of boolean expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45 4.8 bitwise logic and bit operations. . . . . . . ..........................47 4.9 shifting and byte swapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48 4.10 function and procedure calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48 4.11 peripherals and i/o . . . . . . . . . . ................................52 4.12 status register. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55 5 multiply accumulate . . . . . .......................................56 5.1 data formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .56 5.2 mac and umac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..........56 5.3 short multiply accumulate loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .56 5.4 biquad iir filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58 5.5 data vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59 5.6 scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59 5.7 data formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65
3/205 contents ? 6 exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70 6.1 exception levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71 6.2 exception vector table. . . .....................................72 6.3 exception control block and the saved state. . . ....................73 6.4 initial exception handler state . .................................74 6.5 restrictions on exception handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75 6.6 interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . ........................75 6.7 traps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76 6.8 setting up the exception handler . . . . . . . . . . . . ...................76 7 multi-tasking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .78 7.1 processes . . . . . . . . . . . . . . . . . . . . .............................78 7.2 descheduled processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .79 7.3 queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .80 7.4 timeslicing ................................................81 7.5 inactive processes . . . . . . . . . . ................................82 7.6 descheduled process state. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .82 7.7 initializing multi-tasking . . . . . . . . . . . . . . . . . . . . . ..................83 7.8 scheduling kernels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .84 7.9 semaphores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..........84 7.10 sleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .85 8 instruction set reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87 appendices . ...........................................168 a constants and data structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .169 b instruction set summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174 c compiling for the ST20-C1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .178 d glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .187
1.1 ST20-C1 features 4/205 ? 1 introduction this manual provides a summary and reference to the st20 architecture and instruc- tion set for the ST20-C1 core. st20 is a technology for building successful embedded vlsi designs. st20 devices comprise a collection of vlsi macro-cells connected through a high-performance on- chip bus. this architecture allows the easy construction of both general purpose (e.g. st20-mc1 micro-controller) and application specific devices (e.g. st20-tpx digital set top box family). the st20 macro-cell library includes cpu micro-cores, on-chip memories and a wide range of digital and analogue i/o devices. sgs-thomson offers a range of st20 cpu micro-cores, allowing the best cost vs. performance trade-off to be achieved in each application area. this manual describes the ST20-C1 cpu micro-core. st20 devices are available from sgs-thomson and licensed second source vendors. 1.1 ST20-C1 features the ST20-C1 has the following features: ? it is implemented as a 2-way superscalar, 3-stage pipeline, with an internal 16- word register cache. this architecture can sustain 4 instructions in progress, with a maximum of 2 instructions completing per cycle. ? it uses a variable length instruction coding scheme based on 8-bit units which gives excellent static and dynamic code size. instructions take between 1 and 8 units to code, with an average of 1.25 units (10 bits) per instruction. ? it provides flexible prioritized vectored interrupt capabilities. the worst case interrupt latency is 0.5 microseconds (at 33 mhz operating frequency). ? it provides extensive instruction level support for 16-bit digital signal process- ing (dsp) algorithms. ? it is particularly suitable for low power and battery-powered applications, with low core operating power, and sophisticated power management facilities. ? it provides extensive real-time debugging capability through the optional st20 diagnostic controller unit (dcu) macro-cell, which supports fully non-intrusive breakpoints, watchpoints and code tracing. ? it has a flexible and powerful built-in hardware scheduler. this is a light-weight real-time operating system (rtos) directly implemented in the microcode of the ST20-C1 processor. the hardware scheduler can be customized and pro- vides support for software schedulers. ? it provides a built-in user-programmable 32-bit input/output register providing system control and communication capability directly from the cpu.
5/205 1 introduction ? 1.2 manual structure the manual is divided into the following chapters: 1 this introduction chapter, which explains the structure of the book; 2 a notation chapter (chapter 2) which explains the layout and notation conven- tions used in the instruction definitions and elsewhere; 3 an architecture chapter (chapter 3), which explains the structure of the st20- c1 core, the registers, memory addressing, the format of the instructions and the exception handling and process models; 4 four chapters on using the instructions and how the instructions can be used to achieve certain useful outcomes: chapter 4 on the general instructions; chapter 5 on multiply-accumulate; chapter 6 on interrupts and traps; and chapter 7 on processes and support for multi-tasking. 5 an alphabetical listing of the instructions, one to a page (chapter 8). descrip- tions and formal definitions are presented in a standard format with the instruc- tion mnemonic and full name of the instruction at the top of the page. the notation used is explained in detail in chapter 2. in addition there are appendices listing constants and structures, covering issues related to compiling for a ST20-C1 core and listing the instruction set plus a glossary for ST20-C1 terminology.
2.1 instruction listings 6/205 ? 2 notation this chapter describes the notation used throughout this manual, including the meaning of the instruction listings and the meanings and values of constants. 2.1 instruction listings the instructions are listed in alphabetical order, one to a page. descriptions are presented in a standard format with the instruction mnemonic and full name of the instruction at the top of the page, followed by these categories of information: ? code: the instruction code; ? description: a brief summary of the purpose and behavior of the instruction; ? definition: a more formal and complete description of the instruction, using the notation described below in section 2.2; ? status register: a list of errors and other changes to the status register which can occur; ? comments: a list of other important features of the instruction; ? see also: cross references are provided to other instructions with related func- tions. these categories are explained in more detail below, using the and instruction as an example. 2.1.1 instruction name the header at the top of each page shows the instruction mnemonic and, on the right, the full name of the instruction. for primary instructions the mnemonic is followed by `n' to indicate the operand to the instruction; the same notation is used in the descrip- tion to show how the operand is used. an explanation of the primary and secondary instruction formats is given in section 3.4. 2.1.2 code the code of the instruction is the value that would appear in memory to represent the instruction. for secondar y instructions the instruction `operation code' is shown as the memory code e the actual bytes, including any prefixes, which are stored in memory. the value is given as a sequence of bytes in hexadecimal, decoded left to right. the codes are stored in memory in `little-endian' format, with the first b yte at the lowest address. for example, the entry for the and instruction is: code :f9 this means that the hexadecimal byte value f9 would appear in memory for an and .
7/205 2 notation ? for primary instructions the code stored in memory is determined partly by the value of the operand to the instruction. in this case the op-code is shown as `function x ' where x is the function code in the last byte of the instruction. for example, adc ( add constant ) is shown as code: function 8 this means that adc 1 would appear in memory as the hexadecimal byte value 81. for an operand n in the range 0 to 15, adc n would appear in memory as 8 n . 2.1.3 description the description section provides an indication of the purpose of the instruction as well as a summary of the behavior. this may include details of the use of registers, whose initial values may be used as parameters and into which results may be stored. for example, the and instruction contains the following description: description: bitwise and of areg and breg . 2.1.4 definition the definition section provides a formal description of the behavior of the instruction. the behavior is defined in ter ms of its effect on the state of the processor, i.e. the changes in the values in registers and memory before and after the instruction has executed. the effects of the instruction on registers, etc. are given as statements of the following form: register expression involving registers, etc. memory_location expression involving registers, etc. primed names (e.g. areg ) represent values after instruction execution, while names without primes represent values when the instruction execution starts. for example, areg represents the value in areg before the execution of the instruction while areg represents the value in areg afterwards. so the example above states that after the instruction has been executed the register or memory location on the left hand side holds the value of the expression on the right hand side. only the changed registers and memory locations are given on the left hand side of the statements. if the new value of a register or memory location is not given then the value is unchanged by the instruction. the description is written with the main function of the instruction stated first. for example the main function of the add instruction is to put the sum of areg and breg into areg ). this is followed by the other effects of the instruction, such as rotating the stack. there is no temporal ordering implied by the order in which the statements are written.
2.2 instruction definitions 8/205 ? for example, the and instruction contains the following description: definition: areg breg areg breg creg creg areg this says that the integer stack is rotated and areg is assigned the bitwise and of the values that were initially in breg and areg . after the instruction has executed breg contains the value that was originally in creg , and creg has the value that was in areg . the notation is described more fully in section 2.2. 2.1.5 status register this section of the instruction definitions lists an y changes to bits of the status register which can occur. the status register is described in more detail in section 3.3.2. 2.1.6 comments this section is used for listing other information about the instructions that may be of interest. this includes an indication of the type of the instruction: aprimary instructiono e indicates one of the 13 functions which may be directly encoded with an operand in a single byte instruction. asecondary instructiono e indicates an instruction which is encoded using opr . an explanation of the primary and secondary instruction formats is given in section 3.4. the comments section also describes any situations where the operation of the instruction is undefined or invalid and any limits to the parameter values. for example, the only comment listed for the and instruction is: comments: secondary instruction. this says that and is a secondar y instruction. 2.2 instruction definitions the following sections give a full description of the notation used in the formal defini- tion section of the instruction descriptions.
9/205 2 notation ? 2.2.1 the process state the process state consists of the registers ( areg , breg , creg , iptr , tdesc , wptr , and status ), and the contents of memory. a description of the meanings and uses of the registers and special memory locations and data structures is given in section 3.3. 2.2.2 general the instruction descriptions are not intended to describe the way the instructions are implemented, but only their effect on the state of the processor. so, for example, the result of mul is shown in terms of an intermediate result calculated to infinite precision, although no such intermediate result is used in the implementation. comments (in italics ) are used to both clarify the description and to describe actions or values that cannot easily be represented by the notation used here; e.g. take timeslice trap . some of these actions and values are described in more detail in other chapters. an ellipsis is used to show a range of values; e.g. `i = 0..31' means that i has values from 0 to 31, inclusive. subscripts are used to indicate particular bits in a word; e.g. areg i for bit i of areg ; and areg 0..7 for the least significant b yte of areg . note that bit 0 is the least significant bit in a word, and bit 31 is the most significant bit. except for iptr , certain reserved words of memory, and taking exceptions or switching processes, if the description does not mention the state of a register or memory location after the instruction, then the value will not be changed by the instruction. iptr is assigned the address of the next instruction in the code before the instruction execution starts. the iptr is included in the description only when there are additional effects of the instruction (e.g. in the jump instruction). in these cases the address of the next instruction is indicated by the comment ` next instruction '. 2.2.3 undefined v alues some instructions in some circumstances leave the contents of a register or memory location in an undefined state . this means that the value of the location may be changed by the instruction, but the new value cannot be easily defined, or is not a meaningful result of the instruction. for example, when division by zero is attempted, breg and creg become undefined, i.e. they do not contain any meaningful data. an undefined v alue is represented by the name undefined . the values of registers which become undefined as a result of executing an instruc- tion are implementation dependent and are not guaranteed to be the same on different members or revisions of the st20 family of processors. 2.2.4 data types the instruction set includes operations on three sizes of data: 8, 16 and 32-bit objects. 8-bit and 16-bit data can represent signed or unsigned integers and 32-bit data can
2.2 instruction definitions 10/205 ? represent addresses, signed or unsigned integers. generally the arithmetic in signed. in some cases it is clear from the context (e.g. from the operators used) whether a particular object represents a signed or unsigned number. a subscripted label is added (e.g. areg unsigned ) to clarify where necessary. 2.2.5 representing memory the memory is represented by arrays of each data type. these are indexed by a value representing a byte address. access to the three data types is represented in the instruction descriptions in the following way: byte [ address ] references a byte in memory at the given address sixteen [ address ] references a 16-bit half word in memory word [ address ] references a 32-bit word in memory for all of these, the state of the machine referenced is that before the instruction if the function is used without a prime (e.g. word [ address ] ), and that after the instruction if the function is used with a prime (e.g. word [ address ] ). for example, writing a value given by an expression, expr , to the word in memory at address addr is represented by: word [ addr ] expr and reading a word from a memory location is achieved by: register word[ addr ] writing to memory in any of these ways will update the contents of memory, and these updates will be consistently visible to the other representations of the memory. for example, writing a byte at address 0 will modify the least significant byte of the word at address 0. data alignment generally, word and half word data items have restrictions on their alignment in memory. byte values can be accessed at any byte address, i.e. they are byte aligned. 16-bit objects can only be accessed at even byte addresses, i.e. the least significant bit of the address must be 0. 32-bit objects must be word aligned, i.e. the 2 least significant bits of the address must be zero. address calculation an address identifies a par ticular byte in memory. addresses are frequently calculated from a base address and an offset. for different instructions the offset may be given in units of bytes or words depending on the data type being accessed. in order to calculate the address of the data, a word offset must be converted to a byte offset before being added to the base address. this is done by multiplying the offset by the number of bytes per word, i.e. 4. as there are many accesses to memory at word offsets, a shorthand notation is used to represent the calculation of a word address. the notation register @ x is used to
11/205 2 notation ? represent an address which is offset by x words (4 x bytes) from the address in register . for example, in the specification of load non-local there is: areg word[areg @ n] here, areg is loaded with the contents of the word that is n words from the address pointed to by areg , i.e. the word at address areg + 4n. in all cases, if the given base address has the correct alignment then any offset used will also give a correctly aligned address. 2.3 operators used in the definitions a full list of the operators used in the instruction definitions is given in table 2.1. unless otherwise stated, all arithmetic is signed. modulo operators arithmetic is done using modulo arithmetic e i.e. there is no checking for errors and, if the calculation overflows, the result `wraps around' the range of values representable in the word length of the processor e e.g. adding 1 to the address at the top of the symbol meaning unchecked (modulo) integer arithmetic + - / rem signed integer add, subtract, multiply, divide and remainder. if the computation overflows the result of the operation is truncated to the word length. if a divide or remainder by zero occurs the result of the operation is undefined. no errors are signalled. the operator ` - ' is also used as a monadic operator. signed comparison operators < > = comparisons of signed integer values: `less than', `greater than', `less than or equal', `greater than or equal', `equal' and `not equal'. bitwise operators ~ ? >> << >> arith `not', `and', `or', `exclusive or', logical left and right shift and arithmetic right shift operations on bits in words. boolean operators not and or boolean combination in conditionals. table 2.1 operators used in the instruction descriptions
2.3 operators used in the definitions 12/205 ? address map produces the address of the byte at the bottom of the address map. these operators are represented by the symbols ` + ', ` - ', etc. error conditions any errors that can occur in instructions which are defined in ter ms of the modulo operators are indicated explicitly in the instruction description. for example the add instruction indicates the cases that can cause overflow or underflow, independently of the actual addition: if (sum > mostpos) { areg sum - 2 bitsperword status underflo w clear status overflow set } else if (sum < mostneg) { areg sum + 2 bitsperword status underflo w set status overflow clear } else { areg sum status underflo w clear status overflow clear } ... 2.3.1 functions type conversions the following notation is used to indicate the type cast of x to a 16-bit integer: int16 (x) if x is too large or too small to fit into a 16-bit integer then the result of the instruction is undefined. double word splitting where a calculation is performed using a 48-bit or 64-bit value, the value may be split into two words. the function low_word returns the least significant word and the function high_word returns the most significant word.
13/205 2 notation ? 2.3.2 conditions to instructions in many cases, the action of an instruction depends on the current state of the processor. in these cases the conditions are shown by an if clause; this can take one of the following forms: ? if condition statement ? if condition statement else statement ? if condition statement else if condition statement else statement these conditions can be nested. braces, {}, are used to group statements which are dependent on a condition. for example, the cj ( conditional jump ) instruction contains the following lines: if (areg = 0) iptr next instruction + n else { iptr next instruction areg breg breg creg creg areg } this says that if the value in areg is zero, then the jump is taken (the instruction operand, n, is added to the instruction pointer), otherwise the stack is popped and execution continues with the next instruction. 2.4 data structures and constants a number of data structures have been defined in this man ual. each comprises a number of data slots that are referenced by name in the text and the instruction descriptions. these data structures are listed in the tables in appendix a. each table gives the name of each slot in the structure and the word offsets from the base address of the structure. a slot in a data structure is identified using the offset notation descr ibed in section 2.2.5: word[ base_address @ word_offset ]
2.4 data structures and constants 14/205 ? for example, the back pointer of a semaphore structure at address sem would be: word[sem @ s.back] i n addition, several constants are used to identify fixed values for the ST20-C1 processor. all the constants are listed in appendix a. product identity value this is the value returned by the ldprodid instruction. for specific product ids in the st20 family refer to sgs-thomson.
15/205 2 notation ?
3.1 values 16/205 ? 3 architecture this chapter describes the general architectural features of the ST20-C1 core which are relevant to more than one instruction or group of instructions. interrupts and traps are described in chapter 6 and support for multi-tasking is described in chapter 7. other features which are related to specific tasks are descr ibed in chapter 4. a full list of constants and data structures is given in appendix a. the ST20-C1 instruction set covers: ? control flow ? arithmetic and logical operations ? bit field manipulations ? shifting and byte-swapping ? register manipulations ? memory access with various addressing modes and data sizes ? task scheduling ? direct input/output 3.1 values the ST20-C1 core supports data objects of different sizes, either signed or unsigned. the sizes directly supported are bytes (8-bit), half words (16-bit), words (32-bit) and multiple words (64-bit, 96-bit etc.). bytes, half-words and words may be loaded and stored. arithmetic operations are provided for signed words and multiple words. a half word is called a sixteen in the instruction names. the most negative integer (0x80000000) is known as mostneg and the most positive (0x7fffffff) as mostpos . boolean objects, taking one of the values true or false , are also used by some instruc- tions. false is represented by the value 0 and true has the value 1. section 4.7 describes how other values may be implemented for language compilation. several data structures are defined in this man ual. each comprises a number of data words (sometimes called slots ) that are referenced by name in the text and the instruction descriptions and addressed as offsets from the base of the data structure. a full list of these data structures and other constants is given in appendix a. 3.1.1 ordering of information the st20 is little-endian - i.e. less significant data is always held in lower addresses. this applies to bits in bytes, bytes in words and words in memory. hence, in a word of data representing an integer, one byte is more significant than another if its byte selector is larger. figure 3.1 shows the ordering of bytes in words for the st20.
17/205 3 architecture ? figure 3.1 bytes and bits in words for example, the most significant bit of a word is bit 31, and the most significant byte is byte 3, consisting of bits 24 to 31. this ordering is compatible with intel processors, but not motorola or sparc. for compatibility with other devices, a swap32 instruction is provided to reverse the order of bytes within a word. 3.1.2 signed integers and sign extension a signed object is stored in twos-complement format. a signed value may be repre- sented by an object of any size. most commonly a signed integer is represented by a single word, but as explained, it may be stored, for example, in a 64-bit object, a 16-bit object, or an 8-bit object. in each of these formats, all the bits within the object contain useful information. the length of the object that stores a signed value can be increased, so that the object size is increased without changing the value that is represented. this operation is known as sign extension . all the extra bits that are allocated for the larger object, are meaningful to the value of the signed integer; they must therefore be set to the appro- priate value. the value for all these extra bits is the same as the value of the most significant bit - i.e. the sign bit - of the smaller object. the ST20-C1 provides instruc- tions that sign extend byte and half-word objects to words. the example shown in figure 3.2 shows how the value -10 is stored in a 32-bit register, either as an 8-bit object or as a 32-bit object. in this case, bits 31 to 8 are meaningful for the 32-bit object but not for the 8-bit object. these bits are set to 1 in the 32-bit object. 3 21 0 bytes in a word most significant least significant bits in a word most significant least significant 31 0
3.2 memory 18/205 ? figure 3.2 storing a signed integer in different length objects 3.2 memory the st20 processor is a 32-bit word machine, with byte addressing and a 4 gbyte address space. this section explains how data is arranged in that address space. the address of an object is the address of the base, i.e. the byte with the lowest address. 3.2.1 word address and byte selector a machine address, or pointer, is a single word of data which identifies a byte in memory - i.e. a byte address. it comprises two parts, a word address and a byte selector. the byte selector occupies the two least significant bits of the word; the word address the thirty most significant bits. an address is treated as a signed value, the range of which starts at the most negative integer and continues, through zero, to the most positive integer. this enables the standard arithmetic and comparison functions to be used on pointer values in the same way that they are used on numerical values. certain values can never be used as pointers because they represent reserved addresses at the bottom of memory space. they are reserved for use by the processor and initialization. a full list of names and values of constants used in this manual is given in appendix a. in particular, the null process pointer (known as notprocess ) has the value mostneg , since zero could be a valid process address. 3.2.2 alignment a data object is said to be word-aligned if it is at an address with a byte selector of zero, i.e. the full address of the object is divisible by 4. similarly, a data object is said to 11110110 these bit values not related to integer value 0 7 8 31 bit position 11110110 0 7 8 31 bit position 11 1 ... signed integer value (-10) stored as an 8-bit object (byte) signed integer value (-10) stored as a 32-bit object (word)
19/205 3 architecture ? be half-word-aligned if it is at an address with an even byte selector, i.e. the full address of the object is divisible by 2. word objects, including addresses, are normally stored word-aligned in memory. this is usually desirable to make the best use of any 32-bit wide memory. also most instructions that involve fetching data from or storing data into memory, use word aligned addresses and load or store four contiguous bytes. however, there are some instructions that can manipulate part of a word. a half-word object is normally half-word-aligned, so it can be stored either in the least significant 16 bits of a word or in the most significant 16 bits. a data item that is represented in two contiguous words is called a double word object and is normally word-aligned. 3.2.3 ordering of information in memory data is stored in memory using the little-endian rule. objects consisting of more than one byte are stored in consecutive bytes, with the least significant byte at the lowest address and the most significant at the highest address . figure 3.3 shows the ordering of bytes in words in memory. if x is a word-aligned address then the word at x consists of the bytes at addresses x to x+3, where the byte at x is the least significant b yte and the byte at x+3 is the most significant byte of the word. figure 3.3 bytes in words in memory 3.2.4 work space the ST20-C1 uses a stack-based data structure in memory to hold the local working data of a program, called the work space. the work space is a word-aligned collection of 32-bit words pointed to by the work space pointer register ( wptr ). the programmer's model is that all local data is held in the work space, i.e. in memory, and must be brought into the evaluation stack to be operated on, and then written back from the evaluation stack to the work space. x+7 x+6 x+5 x+4 x+3 x+2 x+1 x+0 memory (bytes) x+3 x+2 x+1 x+0 msb lsb 31 24 23 16 15 8 7 0 x+7 x+6 x+5 x+4 msb lsb 31 24 23 16 15 8 7 0 32-bit words x is a word-aligned byte address x + n is the byte n bytes past x
3.3 registers 20/205 ? an implementation of the ST20-C1 core may include a register cache . this provides a mechanism to accelerate access to local work space without changing the programmer's model of how the work space operates or impacting either the excellent code density or low interrupt latency associated with a stack-based instruction set. 3.3 registers this section introduces the ST20-C1 core registers that are visible to the programmer. seven registers, known as process state registers, define the local state of the executing process. these registers are preserved through exceptions. one other register is provided for performing input/output, and is not preserved through excep- tions. all registers are 32-bit. each instruction explicitly refers to specific registers , as described in the instruction definitions. the state of an executing process at any instant is defined b y the contents of the machine registers listed in table 3.1. the registers are illustrated in figure 3.4 and described in the rest of this section. figure 3.4 register set register description areg evaluation stack register a breg evaluation stack register b creg evaluation stack register c iptr instruction pointer register, pointing to the next instruction to be executed status status register wptr work space pointer, pointing to the stack of the currently executing process tdesc task descriptor ioreg input and output register table 3.1 processor registers iptr areg breg creg ioreg tdesc wptr evaluation stack memory program code local program data offset base status task descriptor instruction pointer workspace pointer ST20-C1 core task control block
21/205 3 architecture ? 3.3.1 evaluation stack the registers areg , breg and creg are organized as a three register evaluation stack, with areg at the top. the evaluation stack is used for expression evaluation and to hold operands and results of instructions. generally, instructions may pop values from or push values onto the evaluation stack or both, and do not address individual evalu- ation stack registers. pushing a value onto the stack means that the value initially in breg is pushed into creg , the value in areg is pushed into breg and the new value is put in areg . popping a value from the stack means that a value is taken from areg , the value initially in breg is popped into areg , and the value in creg is popped into breg .the value left in creg varies between instructions, but is generally the value initially in the areg . these actions are illustrated in figure 3.5 and figure 3.6. figure 3.5 pushing a value x onto the evaluation stack figure 3.6 popping a value from the evaluation stack 3.3.2 status register the status register contains status bits which describe the current state of the executing process and any errors which may have been detected. initially the status register is set to the value given in table 7.3. the contents of the status register are summarized in table 3.2 and described in more detail in the following paragraphs. generally the status register is local except for the before areg breg creg after a b c a b x before areg breg creg after a b c c a b
3.3 registers 22/205 ? global interrupt enable and timeslice enable, which are global and carried from one process to another across a context switch. ? the mac_count , mac_buffer , mac_scale and mac_mode fields are used b y the multiply-accumulate instructions to hold initialization data which must be saved when an exception occurs. see chapter 5 for details of multiply accu- mulation. ? the global_interrupt_enable bit enables external interrupts. interrupts remain enabled or disabled until explicitly disabled or enabled again. this bit is global and is maintained when a process is descheduled. ? the local_interrupt_enable enables external interrupts. clearing this bit dis- ables external interrupts until the current process is descheduled. this is needed when a process delegates part of its processing to a peripheral and then deschedules until completion, as described in section 4.11.3. ? overflo w , underflo w and carry bits relating to arithmetic state are kept in the status word. the ST20-C1 maintains astickyo bits in the status word which indicate whether an overflow or underflow has occurred. this allows a complete expression to be evaluated before testing whether an overflow has occurred. overflow and underflo w are chosen as they apply both to addition as well as multiply as opposed to a more traditional method of replicating two bits out of the carry bit numbers full name meaning when set or meaning of value 0-7 mac_count multiply-accumulate number of steps. 8-10 mac_buffer multiply-accumulate data buffer size code. 11 - 12 mac_scale multiply-accumulate scaling code. 13 mac_mode multiply-accumulate accumulator format code. 14 global_interrupt_enable enable external interrupts until explicitly disabled. 15 local_interrupt_enable enable external interrupts. clearing this bit disables inter- rupts until the current process is descheduled. 16 overflo w an arithmetic operation gave a positive overflow. 17 underflo w an arithmetic operation gave a negative overflow. 18 carry an arithmetic operation produced a carry. 19 user_mode a user process is executing. 20 interrupt_mode an interrupt handler is executing or trapped. 21 trap_mode a trap handler is executing. 22 sleep the processor is due to go to sleep. 23 reserved reserved. 24 start_next_task the cpu must start executing a new process. 25 timeslice_enable timeslicing is enabled. 26 - 31 timeslice_count timeslice counter. table 3.2 status register bits
23/205 3 architecture ? chain. in addition, they allow for saturated arithmetic to be implemented rela- tively easily. a (non-sticky) carry bit is provided to allow efficient implementation of long addition and subtraction. the carry bit is only manipulated by the addc and subc instructions allowing the other add instructions to be used in address for- mation of multi-word values where carry propagation is required so that the carry is not lost in the address formation evaluations. ? the user_mode bit indicates when the machine is handling a user process, i.e. a process which is not an exception handler. the interrupt_mode bit indi- cates when the machine is handling an interrupt, or a trap from an interrupt handler and the trap_mode bit indicates when the machine is executing a trap handler. an operating system may need to distinguish between modes to allow it to perform scheduling activities from a trap handler. these bits are also required to enable the eret instruction to determine whether a signal to the interrupt controller is required. ? the sleep bit indicates that the cpu is due to go to sleep, i.e. to turn off its clocks and go into low power mode. this bit is set when the cpu detects there is no user process to execute and is cleared when the cpu goes to sleep. ? the start_next_task bit when set causes the processor to attempt to run the next process from the scheduling queue. ? the timeslice_enable bit and timeslice_count field are used for timeslicing, as described in section 7.4. the instructions to use the status register are described in section 4.12. 3.3.3 the work space pointer all programs need somewhere to store local working data, e.g. local variables in the application code. in the st20 architecture, this local storage is termed the work space of the program. the wptr register is the local work space pointer, which holds the address of the stack of the executing process. the stack is downward pointing, so space is allocated by moving the wptr to a lower address. this address is word aligned and therefore has the two least significant bits set to z ero. when a process is descheduled, the wptr is stored as part of the process descriptor block, which is pointed to by tdesc . the wptr is used as a base for addressing local variables. a word offset from the wptr is the operand for the instructions ldl (load local), stl (store local) and ldlp (load local pointer). the ST20-C1 simplifies the nor mal stack scheme by decoupling the load/store action from the pointer update: ? load-local and store-local instructions access values in the work space with addresses relative to the wptr , but do not change the value of wptr . ? separate instructions ( ajw , gajw ) are provided to update the work space
3.4 instruction encoding 24/205 ? pointer by any amount in one step without needing a series of increments or decrements. on calling a function or procedure, the wptr is normally decreased to a lower address to allocate space for the parameters and local variables of the function. this is performed using the instruction ajw . the wptr is returned to its initial value before returning from the function to free the local work space. 3.3.4 the task descriptor the task descriptor tdesc points to the process descriptor block for the currently executing process. the value held in the tdesc becomes the process identifier when the process is not executing. the process descriptor block is a block of memory whose contents depend on the state of the process. it will generally hold the saved wptr and iptr for the process, and may hold a link to the next process if the process is in a queue of waiting processes. the process descriptor block is described in section 7.2. 3.3.5 io register the bits of the ioreg are mapped to external connections on the ST20-C1 core. they may be used to signal to, or read signals from, peripherals on or off chip. the io instruction is used to read and write to the ioreg and is described in section 4.11. the ioreg is global, and remains unchanged by any context switch. the bits of the ioreg are defined in table 3.3. in some st20 variants, some bits of the io register may be reserved for system use. the reserved bits will be the most significant bits of the appropr iate half word. the number of any such bits is given in the data sheet for each variant. 3.4 instruction encoding the ST20-C1 is a zero-address machine. instruction operands are always implicit and no bits are needed in the instruction representation to carry address or operand location information. this results in very short instructions and exceptionally high code density. the instruction encoding is designed so that the most commonly executed instructions occupy the least number of bytes. this reduces the size of the code, which saves memory and reduces the memory bandwidth needed for instruction fetching. this section describes the encoding mechanism. a sequence of single byte instruction components is used to encode an instruction. the st20 interprets this sequence at the instruction fetch stage of execution. most bits purpose 0-15 output data 16-31 input data table 3.3 ioreg bits
25/205 3 architecture ? programmers, working at the level of microprocessor assembly language or high-level language, need not be aware of the existence of instruction components and do not generally need to consider the encoding. this section has been included to provide a background. appendix c discusses consequential issues which need to be considered in order to implement a code generator. 3.4.1 an instruction component each instruction component is one byte long, and is divided into two 4-bit parts. the four most significant bits of the byte form a function code , and the four least significant bits are used to build an instruction data value as shown in figure 3.7. figure 3.7 instruction format this representation provides for sixteen function code values (one for each function), each with a data field ranging from 0 to 15. instructions that specify the instruction directly in the function code are called primary instructions or functions . there are 13 primary instructions, and the other three possible function code values are used to build larger data values and other instruc- tions. two function code values, pfix and nfix , are used to extend the instruction data value by prefixing. one function code operate ( opr ) is used to specify an instruction indirectly using the instruction data value . opr is used to implement secondar y instruc- tions or operations . 3.4.2 the instruction data value and prefixing the data field of an instr uction component is used to create an instruction data value. primary instructions interpret the instruction data value as the operand of the instruc- tion. secondar y instructions interpret it as the operation code for the instruction itself. the instruction data value is a signed integer that is represented as a 32-bit word. for each new instruction sequence, the initial value of this integer is zero. since there are only 4 bits in the data field of a single instruction component, it is only possible for most instruction components to initially assign an instruction data value in the range 0 to 15. prefix components are used to extend the range of the instruction data value. mnemonic name pfix n prefix nfix n negative prefix table 3.4 prefixing instr uction components function code data 0 3 4 7
3.4 instruction encoding 26/205 ? one or more prefixing components may be needed to create the full instruction data value. the prefixes are shown in table 3.4 and explained below. all instruction components initially load the four data bits into the least significant four bits of the instruction data value. pfix loads its four data bits into the instruction data value, and then shifts this value up four places. consequently, a sequence of one or more prefixes can be used to extend the data value of the following instruction to any positive value. instruction data values in the range 16 to 255 can be represented using one pfix . nfix is similar, except that it complements all 32 bits of the instruction data value before shifting it up, thus changing the sign of the instruction data value. consequently, a sequence of one or more pfix es with one nfix can be used to extend the data value of a following instruction to any negative value. instruction data values in the range -256 to -1 can be represented using one nfix . when the processor encounters an instruction component other than pfix or nfix ,it loads the 4-bit data field into the instruction data value. the instruction encoding is now complete and the instruction can be executed. the instruction data value is then cleared so that the processor is ready to fetch the next instruction component, by building a new instruction data value. for example, to load the constant 0x11, the instruction ldc 0x11 is encoded with the sequence: pfix 1; ldc 1 the instruction ldc 0x2a68 is encoded with the sequence: pfix 2; pfix a; pfix 6; ldc 8 the instruction ldc -1 is encoded with the sequence: nfix 0; ldc f 3.4.3 primary instructions research has shown that computers spend most time executing a small number of instructions such as: ? instructions to load and store from a small number of `local' variables; ? instructions to add and compare with small constants; and ? instructions to jump to or call other parts of the program. for efficiency, in the st20 these are encoded directly as primary instructions using the function field of an instruction component. thirteen of the instruction components are used to encode the most important opera- tions performed by any computer executing a high level language. these are used (in conjunction with zero or more prefixes) to implement the primary instructions. primary instructions interpret the instruction data value as an operand for the instruction. the mnemonic for a primary instruction always includes this operand, shown in this manual as n .
27/205 3 architecture ? the mnemonics and names for the primary instructions are listed in table 3.5. 3.4.4 secondary instructions the st20 encodes all other instructions, known as secondary instructions, indirectly using the instruction data value. the function code opr causes the instruction data value to be interpreted as the operation code of the instruction to be executed. this selects an operation to be performed on the values held in the evaluation stack, so that a further 16 operations can be encoded in a single byte instruction. the pfix instruction component can be used to extend the instruction data value, allowing any number of operations to be encoded. secondary instructions do not have an operand specified b y the encoding, because the instruction data value has been used to specify the operation. to ensure that programs are represented as compactly as possible, the operations are encoded in such a way that the most frequently used secondary instructions are represented without using prefix instructions. for example, the instruction add is encoded by: opr 4 the instruction and is encoded by: opr f9 mnemonic name adc n add constant ajw n adjust work space fcall n function call cj n conditional jump eqc n equals constant jn jump ldc n load constant ldl n load local ldlp n load local pointer ldnl n load non-local ldnlp n load non-local pointer stl n store local stnl n store non-local table 3.5 primary instructions mnemonic name opr n operate table 3.6 operate instruction
3.4 instruction encoding 28/205 ? which is in turn encoded with the sequence: pfix f; opr 9 3.4.5 summary of encoding the encoding mechanism has important consequences. ? it produces very compact code. ? it simplifies language compilation, by providing a completely uniform way of allowing a primary instruction to take an operand of any size up to the proces- sor word-length. ? it allows these operands to be represented in a form independent of the word- length of the processor. ? it enables any number of secondary instructions to be implemented. to aid clarity and brevity, prefix sequences and the use of opr are not explicitly shown in this guide. each instruction is represented by a mnemonic, and for primary instruc- tions an item of data, which stands for the appropriate instruction component sequence. hence the examples above would be just shown as: ldc 17 , add , and and . where appropriate, an expression may be placed in a code sequence to represent the code needed to evaluate that expression.
29/205 3 architecture ?
4.1 manipulating the evaluation stack 30/205 ? 4 using ST20-C1 instructions this chapter describes the purpose for which the sequential instructions are intended, except for the multiply-accumulate instructions, which are described in chapter 5. these instructions are described in the context of their intended use. some instruc- tions are designed for use in a particular sequence of instructions, so this chapter describes those sequences. instructions for exceptions are described in chapter 6 and multi-tasking instructions are described in chapter 7. the architecture of the ST20-C1, including the registers and memory arrangement, is described in chapter 3. 4.1 manipulating the evaluation stack the evaluation stack consists of the registers areg , breg and creg . the general action of the evaluation stack is described in section 3.3.1. instructions are provided for shuffling and re-order ing the values on the evaluation stack, as listed in table 4.1. rot pops the value from areg off the evaluation stack and rotates it into creg , and arot pushes the value from creg onto the stack. rev swaps the areg and breg , and dup pushes a copy of areg onto the stack. table 4.2 shows how each of these affects the evaluation stack. each row shows the contents of the evaluation stack after one of these instructions is executed if the initial values of the areg , breg and creg are a, b and c respectively. many instructions leave the initial areg in creg . this value may be restored into the areg by using arot . mnemonic name rot rotate stack arot anti-rotate stack dup duplicate stack rev reverse stack table 4.1 evaluation stack manipulation instructions instruction areg breg creg rot bca arot cab rev bac dup aab table 4.2 evaluation stack manipulation
31/205 4 using ST20-C1 instructions ? 4.2 loading and storing the loading and storing instructions are listed in table 4.3. on the st20, the term loading means pushing a value onto the evaluation stack. the value to be loaded may be a value read from memory, a constant, a copy of another register or a calculated value. storing means popping a value from the evaluation stack. the value may be written into memory or written into another register. the eval- uation stack is described in section 3.3, and evaluation of expressions is described in section 4.3. relative addresses are used for accessing memory in order to reduce code size, as the operand values are smaller than full machine addresses. data structures are word-aligned, so relative addresses can be word offsets, reducing the operand size further. the most common operations performed by a program are loading and storing of a small number of variables, and loading small literal values. 4.2.1 loading constants one primary instruction ldc is provided for loading a general constant, for initializing a variable or register or for a constant in an expression. 4.2.2 local and non-local variables when loading from and storing to memory, the st20 distinguishes between local and non-local addressing. local addressing means that the address is given as a word offset from the wptr . non-local addressing means that the address is given as a word offset from the areg . in practice, the wptr points to the stack, so local addressing is mnemonic name description ldc n load constant load the constant n . ldl n load local load the value from n words above wptr . stl n store local store a value to n words above wptr . ldnl n load non-local load the value from n words above areg . stnl n store non-local store a value to n words above areg . lbinc load byte and increment load a byte and increment the address by 1 byte. sbinc store byte and increment store a byte and increment the address by 1 byte. lsinc load sixteen and increment load a half word and increment the address by 2 bytes. lsxinc load sixteen sign extended and increment load a half word and sign extend to 32 bits and increment the address by 2 bytes. ssinc store sixteen and increment store a half word and increment the address by 2 bytes. lwinc load word and increment load a word and increment the address by 4 bytes. swinc store word and increment store a word and increment the address by 4 bytes. table 4.3 loading and storing instructions
4.2 loading and storing 32/205 ? normally used for local variables on the stack while non-local addressing is normally used for all other variables. the primary instructions ldl and stl perform loading and storing of local variables. for example to load a value x words above the wptr and write to a location y words above the wptr : ldl x; stl y; the primary instructions ldnl and stnl perform loading and storing of non-local vari- ables. for example, to load a value x above a base address x_base and store to a location y words above y_base , where x_base and y_base are held in local variables: ldl x_base; ldnl x; ldl y_base; stnl y; note that for the purposes of this manual, ld x denotes loading the value from a variable x , where x may be a local or non-local variable, so either ldl or ldnl may be used as appropriate. similarly st x denotes storing a value into a variable x , where x may be a local or non-local variable, so either stl or stnl may be used. 4.2.3 byte and half-word values instructions are provided for loading and storing byte and half-word variables. in each case, the address is initially in the areg and is incremented by the size of the object, so that repeated loads and stores can be used to copy a block of memory. the load instructions place the loaded value in the areg , the incremented address in the creg and leave the breg unaffected. the store instructions write the initial breg into memory at the address in the areg , leaving the incremented address in the breg , the initial creg in the areg and the initial breg pushed down to the creg . byte loading and storing lbinc loads the byte at the address in areg, into the evaluation stack. lbinc replaces the address in areg with the byte stored at that address, treating it as an unsigned integer by setting the twenty-four most significant bits in areg to 0. the incremented address is left in creg . sbinc writes the least significant b yte in breg to the location addressed by areg . the address is incremented by 1 and put in the breg . half-word loading and storing lsinc and lsxinc load the half-word object at the address in areg , into the evaluation stack. lsinc replaces the address in areg with the half word, treating it as an unsigned integer by setting the sixteen most significant bits in areg to 0. lsxinc is similar to lsinc , but treats the half-word as a signed integer in twos-complement format, and hence sign extends the representation by setting the sixteen most significant bits in areg to the same value as the most significant bit of the half-word object. sign extension is discussed in section 4.4.6.
33/205 4 using ST20-C1 instructions ? ssinc writes the half word in the two least significant b ytes of breg to the location addressed by areg . 4.2.4 memory block copy a block memory copy may be implemented using the instructions lwinc and swinc . these instructions load or store a word, and increment the addresses used. to copy n bytes from source to destination , where source and destination are both word-aligned, a loop should be written, using the temporary variable limit , as in the following code: ld source; ld n; ld destination add; stl limit loop: lwinc; rev; swinc ldl limit; arot gt; cj end; j loop; end: this is the most efficient method of copying, since it reads and writes full words, making the best use of any 32-bit memory. however, this is not always possible if the alignment of the source and destination blocks are different. in that case the byte or half-word load and store should be used. 4.3 expression evaluation expression evaluation and address calculation is performed using the evaluation stack. for example, the evaluation of operations with two integer operands is performed by instructions that operate on the values of areg and breg . the result is left in areg . arithmetic and boolean calculations are considered in sections 4.4 and 4.7 respec- tively. this section describes how the evaluation stack is used. loading and storing instructions are described in section 4.2. in this and subsequent sections, in examples of assembly code, a single letter or iden- tifier wr itten as an instruction is either an expression or a segment of code. if it is an expression then it means `evaluate the expression and leave the result in the areg . 4.3.1 using the evaluation stack a compiler normally loads a constant expression c using ldc : ldc c loading from a constant table is described in section 4.3.3. an expression consisting of a single local variable is loaded using ldl x methods for loading non-local variables are discussed in section 4.2, and array elements in section 4.5.
4.3 expression evaluation 34/205 ? evaluation of expressions sometimes requires the use of temporary variables in the process work space, but the number of these can be minimized by careful choice of the evaluation order. the details of how this is achieved by a compiler are described in appendix c in section c.3. 4.3.2 loading operands the three registers of the evaluation stack are used to hold operands of instructions. evaluation of an operand or parameter may involve the use of more than one register. care is needed when evaluating such operands to ensure that the first oper and to be loaded is not pushed off the bottom of the evaluation stack by the evaluation of later operands. the processor does not detect evaluation stack overflow. three registers are available for loading the first operand, two registers for the second and one for the third. consequently, the instructions are designed so that creg holds the operand which, on average, is the most complex, and areg the operand which is the least complex. in some cases, it is necessar y to evaluate the areg and breg operands in advance, and to store the results in temporary variables. this can sometimes be avoided using the reverse instruction. any of the following sequences may be used to load the operands a , b and c into areg , breg and creg respectively. 1c;b;a; 2 c; a; b; rev; 3 b; c; rev; a; 4 a; c; rev; b; rev; the choice of loading sequence, and of which operands should be evaluated in advance is determined by the number of registers required to evaluate each of the operands. the algorithm used by compilers is given in appendix c in section c.4. 4.3.3 tables of constants the ST20-C1 instruction set has been optimized so that the loading of small constants can be coded compactly e for example it allows the loading of constants between 0 and 15 to be coded in a single byte. analysis of programs shows that such small constants occur markedly more frequently than large constants. however when a large constant does need to be loaded the necessary prefix sequence may be long. other techniques may be more efficient in these cases . a simple mechanism to increase the code compactness is to use a table of constants. this is implemented by storing all the long constants into a look-up table. this table and all its constant entries must be aligned on a word boundary. the address of this table is held in a local variable which is used to index the array. then to load the
35/205 4 using ST20-C1 instructions ? constant from the n th entry in the constant table stored at address constants_ptr the following code would be used: ldl constants_ptr ; ldnl n; where the instruction ldnl n is explained in section 4.2.2. this code sequence only takes 2 bytes, provided constants_ptr is less than 16 words from the work space pointer address and there are no more than 16 word-length constants. at worse it is unlikely to take more than 4 bytes. hence, if a constant takes 4 or more bytes to load using ldc then this sequence often improves code compact- ness e especially if the constant is used more than once. 4.3.4 assignment single words, half words and bytes may be assigned using the load and store instruc- tions described in section 4.2. word assignment if x and y are both single word variables and e is a word valued expression then word assignments are compiled as x = y compiles to ld y; st x; x = e compiles to e; st x; byte assignment if a and b are both single byte variables and e is a byte valued expression then byte assignments are compiled as b = a compiles to address(a); lbinc; address(b); sbinc; b = e compiles to e; address(b); sbinc; where address(variable) is the address of variable. forming addresses is discussed in section 4.5. half word assignment if a and b are both half-word variables and e is a half-word valued expression then half-word assignments are compiled as b = a compiles to address(a); lsinc; address(b); ssinc; b = e compiles to e; address(b); ssinc; where address(variable) is the address of variable. forming addresses is discussed in section 4.5. 4.4 arithmetic this section describes the use of the arithmetic instructions except for the multiply- accumulate instructions, which are described in chapter 5, and forming addresses, which is described in section 4.5. boolean expression evaluation is discussed in
4.4 arithmetic 36/205 ? section 4.7, and the general principles of expression evaluation are described in section 4.3. 4.4.1 addition, subtraction and multiplication single length signed arithmetic is provided by the operations listed in table 4.4. each of these instructions except smul can signal overflow or underflow by setting the appropriate bit in the status register. an overflow occurs if the result is greater than mostpos and an underflow if it is less than mostneg . if overflow or underflow occurs, then the 32 least significant bits of the full result are left in the areg . the overflow and underflow are `sticky', so when one has been set, it is not cleared and the other cannot be set by subsequent arithmetic. the overflow and underflo w bits may be used for saturated arithmetic, as described in section 4.4.3. the primary instruction adc n adds the constant value n to areg . breg and creg are unaffected. this is used for incrementing and decrementing variables and counters. if op is one of add , sub , mul or smul , then the instruction sequence ldl x; ldl y; op; evaluates the expression xopy i.e. it takes the value in breg as the left hand operand and the value in areg as the right hand operand, and loads the result into areg . the content of creg is popped into breg and the initial areg is rotated into creg . smul multiples two half-word values producing a 32-bit result. it cannot overflow or underflow and is faster than mul . 4.4.2 division and remainder division and remainder are performed using the operations listed in table 4.5. mnemonic name adc n add constant add add sub subtract mul multiply smul short multiply table 4.4 single length signed integer arithmetic instructions mnemonic name divstep divide step unsign unsign argument table 4.5 division and remainder instructions
37/205 4 using ST20-C1 instructions ? each divstep generates four bits of the unsigned quotient, so eight divstep s are needed for a full 32-bit unsigned division, and will also generate a remainder. the result of the division is the integer division rounded towards zero (truncated). the quotient is left in breg , and the remainder in creg , so a rotation pops the quotient into the areg . unsign is used to separate the sign from the magnitude of the operands before performing the division. division is then performed on the magnitudes, and the signs of the results may be derived from the signs of the operands. overflow can occur only if the divisor ( areg ) is zero, or if the dividend ( breg )is mostneg and the divisor is -1. divstep does not detect these cases, and does not set any status bits, so a check should be applied before performing the division. the following code sequence performs the integer division a/b . the signed quotient is left in areg . a; b; ldc 0; arot; unsign; arot; unsign; cj pos; ldc 0; rot; divstep; divstep; divstep; divstep; divstep; divstep; divstep; divstep; rot; not; adc 1; j end; pos: rot; divstep; divstep; divstep; divstep; divstep; divstep; divstep; divstep; rot; end: the following code sequence performs the remainder a rem b . the signed remainder is left in areg . a; b; ldc 0; rev; unsign; eqc 2; arot; unsign; cj pos; divstep; divstep; divstep; divstep; divstep; divstep; divstep; divstep; arot; not; adc 1; j end; pos: rot; divstep; divstep; divstep; divstep; divstep; divstep; divstep; divstep; arot; end: 4.4.3 saturated arithmetic in saturated arithmetic, when an overflow or underflow occurs the result is set to the most positive or most negative possible result respectively, instead of the least signifi- cant bits of the full result. this ensures that the result is as near as possible to the real value and prevents glitches caused by wrap-around.
4.4 arithmetic 38/205 ? saturated arithmetic is achieved on the ST20-C1 by evaluating an expression and then performing the saturate instruction. if an overflow or underflow has occurred then the corresponding status bit will have been set, which will cause saturate to change the value in areg to the most positive or most negative value respectively. saturate clears the overflow and underflow bits. for example, to perform a saturated multiply of a and b : ld a; ld b; mul; saturate; 4.4.4 unary minus the expression (-e) can be evaluated with overflow signalling by: e; not; adc 1; or ldc 0; e; sub; the first sequence , using not , requires one less stack register than the second. not is a bitwise inversion which is described in section 4.8. 4.4.5 long arithmetic the long arithmetic instructions are listed in table 4.6. multiple length addition and subtraction multiple length addition or subtraction are performed using addc and subc , executed once for each word of the result. for both instructions, the carry (or borrow) is held in the carry bit of the status register. this keeps the carrying separate from overflow, so address calculations may be safely performed using add , sub and wsub without affecting the carry. the addc instruction forms ( breg + areg )+ status carry leaving the least significant word of the result in areg and the most significant (carr y) bit in the carry bit of the status register. the areg is rotated into the creg . similarly, the subc instruction forms ( breg - areg )- status carry leaving the least significant word of the result in areg and the borrow bit in the carry bit of the status register. the areg is rotated into the creg . addition of two double length unsigned values, x and y , giving z , without overflow signalling can therefore be compiled as follows mnemonic name addc add with carry subc subtract with carry umac unsigned multiply accumulate table 4.6 long arithmetic instructions
39/205 4 using ST20-C1 instructions ? ldc 0; ldl x lo ; ldl y lo ; addc; stl z lo ; ldl x hi ; ldl y hi ; addc; stl z hi the subscripts `lo' and `hi', used here and in subsequent text, specify the least and most significant word respectively of the double word variable with which they are associated. subtraction of two double length values, y from x giving z , without overflow signalling is compiled as ldc 0; ldl x lo ; ldl y lo ; subc; stl z lo ; ldl x hi ; ldl y hi ; subc; stl z hi overflow signalling for signed arithmetic may be added by performing an extra addc or subc to produce a final w ord which contains only a sign (0 for positive or -1 for negative) unless an overflow has occurred. for example, the following code could be used to perform double length signed addition with overflow signalling: clear carry, overflow and underflow status bits ld x lo; ld y lo; addc; st z lo; ld x hi; ld y hi; addc; st z hi; ldc 0; dup; addc; dup; adc #7ffffff; - overflows if and only if carry word > 0 rev; adc #8000001; - underflows if and only if carry word < -1 multiple length multiplication the umac instruction multiplies two single word unsigned operands in areg and breg , and adds the single word carry operand in creg to form a double length unsigned result. the more significant (carr y) word of the result is left in breg , the less significant in areg . no overflow can be signalled by this instruction. multiplication of a single length unsigned value x by a double length unsigned value y (leaving the `carry' in areg ) can be performed by: ldc 0; ldl x; ldl y lo ; umac; stl z lo ; ldl x; ldl y hi ; umac; stl z hi double length unsigned multiplication is more complex. the product of two unsigned double length words x and y can be expressed as: x*y=(x hi *2 32 +x lo )*(y hi *2 32 +y lo ) =(x hi *y hi )*2 64 +(x hi *y lo +x lo *y hi )*2 32 +(x lo *y lo ) this can be coded as follows: ldc 0; ldl x lo ; ldl y lo ; umac; stl z 0 ldl x lo ; ldl y hi ; umac; rev; stl z 2
4.4 arithmetic 40/205 ? ldl x hi ; ldl y lo ; umac; stl z 1 ; ldl x hi ; ldl y hi ; umac; rev; stl z 3 ; ldc 0; rev; ldl z 2 ; addc; stl z 2 ; ldl z 3 ; addc; stl z 3 this gives a quadruple length unsigned result z , where z 0 is the least significant and z 3 the most significant word of z . 4.4.6 object length conversion object length conversion operations are provided by the instructions listed in table 4.7. section 3.1 explains that data can be represented in data objects of various sizes. this section describes the instructions that can be used to convert between these representations. most of the ST20-C1 integer arithmetic instructions operate on signed integers held in the evaluation stack registers as 32-bit objects, and produce results in this form. object length conversion is important for conversion of high level language data types. the ST20-C1 therefore provides instructions that allow a byte or half-word signed integer to be sign extended to 32-bits by copying the sign bit to all the bits that were previously not significant, as shown in figure 3.2. the sign extension is performed on the value in the areg and the result is placed in the areg . the other registers are not affected. xbword extends a signed byte to a word by copying bit 7 into bits 8 to 31. xsword extends a signed half-word to a word by copying bit 15 into bits 16 to 31. lsxinc loads a sixteen bit value, sign extends it to 32 bits and increments the address by two bytes. this is the same as: lsinc; xsword; mnemonic name xbword sign extend byte to word xsword sign extend sixteen to word table 4.7 object length conversion instructions
41/205 4 using ST20-C1 instructions ? 4.5 forming addresses the addressing instructions provide access to items in data structures using short sequences of single byte instructions. these instructions are listed in table 4.8. 4.5.1 the address of a variable the absolute address of a local work space location is loaded using the ldlp primary instruction. ldlp 0 can be used to load the value in the wptr . the ldnlp primary instruction is provided to calculate the absolute address of a non- local variable. the meaning of local and non-local is described in section 4.2. 4.5.2 the address of an instruction the address of a location in the program being executed can be obtained by the ldpi operation as follows. the address of the location x bytes past the next instruction (which is itself pointed to by the instruction pointer register) can be pushed onto the evaluation stack by ldc x; ldpi for example, the address of a label l can be loaded by ldc (l-m); ldpi m: where the label m is the address of the instruction that follows the ldpi instruction. first the offset in bytes from m to l is loaded into areg . the ldpi then uses this offset and the value in the instruction pointer register (which will be the address of label m )to load the address of label l into areg . this technique is useful for generating relocat- able code. breg and creg are unaffected. 4.5.3 arrays the wsub instruction interprets areg as the address of the beginning of a vector of word-sized data objects, and breg as an index into that vector. after execution, areg holds the address of the indexed element, and creg is popped into breg , leaving areg rotated into creg . the operation performed by wsub is to multiply the integer in breg by four and to add this to the address in areg (without overflow checking). mnemonic name meaning ldlp n load local pointer load the value wptr +4 n . ldnlp n load non-local pointer load the value areg +4 n . ldpi n load pointer to instruction load the value iptr + n. wsub word subscript load the value areg +4. breg . table 4.8 addressing instructions
4.5 forming addresses 42/205 ? access to a component of an array can be split into two sections; first the address of the component must be constructed, and then the transfer of data to or from that component must be performed. evaluating a subscript array subscripts can be evaluated efficiently using the smul or mul instruction. if array a has been declared by int a [ s 1 ] ... [ s n ]; where s i ( i = 1..n ) are the dimensions, then one way of arranging this in memory is to have all elements of the array in a contiguous block. for the purposes of this section, suppose that the elements in the last dimension are stored adjacently; otherwise change the order of the dimension subscripts. for example figure 4.1 shows the elements of a particular three dimensional array ( array ) stored in this way. figure 4.1 a possible method of storing an array of integers if an access is required to the following array element a [ e 1 ] ... [ e n ] then the code to evaluate the subscript is e 1 ; ldc s 2 ; mul; e 2 ; add; ldc s 3 ; mul; e 3 ; add; ... ldc s n ; mul; e n ; add; for example to evaluate the subscript for element array[x][y][z] , (where array is declared as in figure 4.1) the code sequence is ld x; ldc 2; mul; ld y; add; ldc 3; mul; ld z; add; if x is 1, y is 0 and z is 2, then this evaluates to 8, which as can be seen from figure 4.1, is the correct offset from the base of the array. array[1][1][1] array[1][1][0] array[1][1][2] array[1][0][1] array[1][0][0] array[1][0][2] array[0][1][1] array[0][1][0] array[0][1][2] array[0][0][1] array[0][0][0] array[0][0][2] int array[ 2 ][ 2 ][ 3 ]; increasing memory addresses contiguous locations for words in memory space
43/205 4 using ST20-C1 instructions ? accessing a word addressed array let wa_ptr be a pointer to an array wa that starts at a word boundary, and in which all component types are measured in words. let e be a subscript expression. the address of component e of wa is e; wa_ptr; wsub; or if e is a constant expression this can be optimized to: wa_ptr; ldnlp e; accessing a byte addressed array similarly, let ba_ptr be a pointer to an array ( ba ) which may start at any byte location, and in which each component type is measured in bytes. let e be a subscript expres- sion. the address of component e of ba is: e; ba_ptr; add; 4.6 comparisons and jumps this section describes the arithmetical comparison instructions and their use in condi- tional program behavior. unconditional jumps are also described. functions and procedures are described in section 4.10, and evaluation of boolean expressions is described in section 4.7. comparisons, conditional behavior and jumps are provided by the instructions listed in table 4.9. 4.6.1 representation of true and false the st20 uses 0 as false and 1 as true . these values are generated by predicate operations (for example comparisons). they can be loaded with single byte load constant instructions. mnemonic name eqc n equal to constant gt greater than gtu greater than unsigned order order orderu order unsigned cj n conditional jump jn jump jab jump absolute table 4.9 comparison and jump instructions
4.6 comparisons and jumps 44/205 ? implementation of languages with different representations of true and false it is easy to implement programming languages that use a different representation of true and false . for example, using eqc x; not; adc 1 in place of eqc x and gt; not; adc 1 in place of gt , does not affect the representation of a false result, but changes the representation of true to -1, which is used in some programming languages. 4.6.2 comparison the primary instruction eqc n loads areg with a truth value e true if areg is initially equal to the instruction operand ( n ), false otherwise. breg and creg are unaffected. gt and gtu take integer operands in areg and breg and produce a boolean result which is loaded into areg . they also load the value in creg into breg , saving a copy of the initial areg in creg . the gt instruction loads areg with true if breg > areg , false otherwise, treating areg and breg as signed values. similarly gtu loads areg with true if the unsigned value of breg is greater than the unsigned value of areg ; false otherwise. 4.6.3 jump and conditional jump there are two relative jump instructions; both are primary instructions. the unconditional jump instruction, jn , adds its operand ( n ) to the address of the instruction immediately following it and puts the result into iptr , thus transferring execution to another part of the program. the conditional jump instruction, cj n , performs a jump if the value in areg is 0 and does not affect the evaluation stack. if the value in areg is not 0 cj rotates the value in areg to the bottom of the evaluation stack and continues with the next instruction. consequently cj n serves as `jump if false ' provided that the language being imple- mented interprets 0 as false (see section 4.6.1). 4.6.4 conditional transfer of control the conditional expressions used in a conditional branch of an if construct are compiled using the conditional jump. the statement: if ( e ){ p } this compiles to: e; cj l; p; j endif; l:
45/205 4 using ST20-C1 instructions ? where the label endif: is at the end of the code for the if construct. the compilation of a while loop is shown by the following example. while ( e ){ p } this compiles to: l: e; cj endwhile p; timeslice; j l endwhile: note that this loop includes a timeslice instruction. this causes the current process to be descheduled if a timeslice is due and timeslicing is enabled. the presence of this ensures that the process cannot occupy the cpu for too long provided timeslicing is enabled. it is good practice for multi-tasking programs to include a timeslice instruction in every loop. timeslicing is described in section 7.4. single task programs do not need to timeslice, but should have timeslicing disabled, so the timeslice instruction has no effect. a repeat .. until loop is shown by the following example. repeat { p } until e this compiles to: jk l: e; eqc 0; cj end k: p; timeslice; j l end: 4.6.5 ordering instructions two instructions are provided to select the smaller of two values. if breg is smaller than areg as a signed integer, order will swap areg and breg ; otherwise order will have no effect. this can be used to find the minimum of two signed variables: ldl a; ldl b; order; stl minimum; stl maximum similarly orderu can be used to find the minimum or maximum of two unsigned values 4.7 evaluation of boolean expressions this section describes the operations using the logical true and false values, as used with the conditional jump cj . conditional behavior and comparisons are described in section 4.6. bitwise boolean operations are described in section 4.8. general issues concerning expression evaluation are discussed in section 4.3.
4.7 evaluation of boolean expressions 46/205 ? the following shows the correspondence between c logical expressions and ST20-C1 instructions. x and y represent expressions,and k represents a constant. the symbol ` ? ' is a logical not (see section 4.7.1). true = ldc 1 false = ldc 0 !x = ? (x) x==y = x; y; sub; eqc 0 x!=y = ? (x; y; sub; eqc 0) x==k = x; eqc k x!=k = ? (x; eqc k) x>y = x; y; gt x=y = ? (y; x; gt) x<=y = ? (x; y; gt) further optimizations can be made to the `not equals' comparison when followed by a conditional jump. x != y; cj l = x; y; sub; cj l x != 0; cj l = x; cj l 4.7.1 evaluation of not if zero represents false and 1 represents true, then logical not can be performed by eqc 0 . 4.7.2 evaluation of and and or for evaluation of logical and and or operations, the instruction sequence depends on whether strict or non-strict evaluation is used, i.e. whether both operands are always evaluated. this is important if side-effects may occur, such as a trap, or if the second operand is not always defined, as in: if ((ptr != null) && (ptr->tag == tag_val)) ... in this example, ptr->tag is not defined if ptr is null . for languages such as ansi c, non-strict evaluation is required, so the following short-cuts must be used: x or y = ? ( ? (x); cj l; ? (y); l:) x and y = x; cj l; y; l: for non-strict evaluation, the following laws should be applied to the compilation of conditional expressions before code is generated to ensure that the jump is taken as early as possible: ? (x and y) = ( ? x) or ( ? y) [= ? (x; cj l; y; l:) ] ? (x or y) = ( ? x) and ( ? y) [= ? ( x); cj l; ? ( y); l: ] (x or y); cj l = ( ? x); cj m; y; cj l; m: (x and y); cj l = x; cj l; y; cj l
47/205 4 using ST20-C1 instructions ? in other languages, evaluation of boolean expressions may be strict (for example, ada gives the programmer the choice) and so both expressions in dyadic logical opera- tions may need to be evaluated. where false is represented by 0, and true is represented by any fix ed bit pattern other than 0 (e.g. true is always 1, or true is always -1), then the following transformations apply: x or y = x bitor y x and y = x bitand y and the bitwise instructions given in section 4.8 can be used: note that even for some non-strict evaluations, the above sequence may be prefer- able. where y is a simple boolean expression such as a local variable, its evaluation does not cause any side-effects, and so it does no harm to implement a non-strict evaluation using a bitwise operation. 4.8 bitwise logic and bit operations bitwise logic and bit operations are provided by the instructions listed in table 4.10. the not operation has only one operand that is taken from areg . the result of this, which is a bitwise inversion of all bits in the operand, is loaded into areg , leaving breg and creg unaffected. and , or and xor are bitwise logical operations on two operands that are taken from areg and breg . for each, the result is loaded into areg . the data previously held in creg is popped into breg and the initial areg is left in creg . these operations are commutative. bitld , bitst and bitmask are used for setting, clearing and testing bits of a word. bitld returns the value of a single bit from a value in breg , bitst sets or clears a single bit and bitmask creates a mask with a single bit set. in each case the bit number is initially in areg and the result is put in areg . for bitld and bitst , the value containing the bit to be tested, set or cleared is initially in breg . mnemonic name and and or or xor exclusive or not bitwise not bitld bit load bitst bit store bitmask bit mask rmw memory read modify write table 4.10 bitwise logic and bit instructions
4.9 shifting and byte swapping 48/205 ? 4.8.1 memory bit test and clear or set bits of a word in memory may be tested and set or cleared by the instruction rmw . the address of the memory word is held in areg and a bit masks in breg and creg . rmw clears the bits of the memory word that are set in creg , and then sets the bits of the memory word that are set in breg .the initial memory word is loaded into areg , with areg pushed down to breg and breg pushed down to creg . 4.9 shifting and byte swapping the shift and byte swapping operations are provided by the instructions listed in table 4.11. the shift operations ( shl , shr and ashr ) shift the operand in breg by the number of bits specified b y the unsigned integer in areg and put the result in areg . shl and shr fill the vacated bit positions with zero bits, while ashr fills the v acated bits with copies of bit 31, which is the original sign bit. if areg is zero, the result is the initial value of breg . when the value in areg is greater than the number of bits in the object being shifted, the result of the operation is undefined. the data previously held in creg is popped into breg , and the initial breg is left in the creg . swap32 reverses the order of the bytes in areg by swapping byte 0 with byte 3 and swapping byte 1 with byte 2. 4.10 function and procedure calls the function and procedure call operations are provided by the instructions listed in table 4.12. the primary instruction fcall n calls a function or procedure. it stores the instruction pointer (which holds the return address) in the word pointed to by the wptr . the operand to the call - n - is added to the address of the next instruction to produce the address of the first instr uction of the procedure or function being called. since the call address is relative, the code is relocatable. mnemonic name shl shift left shr shift right ashr arithmetic shift right swap32 byte swap 32 table 4.11 shifting and byte swapping instructions mnemonic name fcall function call jab jump absolute ajw adjust work space gajw general adjust workspace table 4.12 function and procedure instructions
49/205 4 using ST20-C1 instructions ? a function called using fcall must have a fixed offset at compile time. jab is used for calling functions and procedures at dynamically calculated addresses, for example when using function pointers. the jab instruction is also used to perform the return. the return address must have been restored with a ldl from the stack into the areg . a procedure or function that requires local work space will normally include ajw instructions to allocate and deallo- cate space. when the jab instruction is executed, the programmer must ensure that: ? the areg holds the return address; ? any workspace claimed by the procedure should have been released so that the wptr has returned to the value it held at the start of the procedure. the jab instruction uses one word of the evaluation stack, so the other two words can therefore be used to return up to two values to the calling code, including a pointer to a block of additional data to be returned. 4.10.1 adjusting work space the primary instruction ajw is used to perform a relative adjustment to the stack pointer wptr to: ? create work space on the stack at the beginning of the function and ? return the work space pointer at the end of the function. ajw n increases the value of the workspace pointer by the number of words in its operand value, n . work space is created at the beginning of a function or procedure with a negative operand and released before returning with a positive operand. the amount of extra work space needed will normally include: ? space to save any parameters passed in the evaluation stack; ? space for local variables and temporaries; ? space for any hidden system variables such as the static chain. for example, a function with w words of local work space might be: t myfunction (param_1, param_2) { local variable declarations ; p; return (e); } this can be compiled as: ajw -w; stl param_1; stl param_2; p; e; ajw w;
4.10 function and procedure calls 50/205 ? ldl 0; jab; ST20-C1 processors may have a workspace cache which holds a copy of a few words at the bottom of the work space. this cache is transparent to the programmer but may substantially improve performance. it is refilled whene ver the wptr is adjusted, so the ajw instruction should not be used excessively. 4.10.2 parameters it is convenient to load the first three parameters of the procedure or function into the evaluation stack registers, and to arrange the work space of the calling code so that the additional parameters can be stored in locations 1, 2, ... of the work space before the procedure is called. location zero of the work space is used for the return address. this is illustrated in figure 4.2, which shows a possible work space layout for a function or procedure with six parameters and four local variables. figure 4.2 example function or procedure workspace to enable the procedure to access non-local variables the parameters of a procedure may include a link to the environment in which the procedure was declared. 4.10.3 returning results up to two results of size less than or equal to the word length of the processor can be returned from a function in the evaluation stack e the jab instruction uses the third register. further results, or results larger than the word length, can be returned by passing into the function the addresses of locations to store these results as extra parameters. wptr in calling code return iptr param 3 param 2 param 4 param 5 param 6 param 1 variable 1 variable 2 variable 3 variable 4 wptr in function or procedure
51/205 4 using ST20-C1 instructions ? a c function is used for purposes of illustration. for simplicity, it is assumed that the single result can be returned in the evaluation stack: ajw -local_variables-1; p; e; ldl local_variables; ajw local_variables+1; jab; one of the loading sequences described earlier may be required if the expressions returned in the registers contain evaluations. 4.10.4 calling a function the first three par ameters should be loaded into the evaluation stack before the fcall instruction. these parameters can be stored as local variables after the workspace pointer has been moved down, to make the best use of the work space cache. the remainder of the parameters passed should be loaded into the work space before fcall is executed. when the function returns, the results whose addresses were passed will already have been stored so all that remains is to store up to 2 results returned in the evalua- tion stack. for example the function call v = f ( e 1 , ... , e n ) could be compiled by e 3 ; stl 0; . . . ; e n ; stl (n-3); e 2 ;e 1 ; static_link; fcall f; stl v; the compiler must have already allocated sufficient workspace for the parameters that are stacked explicitly. single result functions in most programming languages, a function that returns a single result can be used in an expression as well as in an assignment. a common form of function returns a single value contained in a word e the mechanism described above will return this in areg . when compiling expressions, (using the algorithm described in section c.3 in appendix c) the depth of such a function call should be taken as being infinite e i.e. deeper than any other form of expression. this is because the function call will always lose any other information in the registers. by giving it infinite depth the expression compilation algorithm will never call a function while another expression result is being held in a register.
4.11 peripherals and i/o 52/205 ? 4.10.5 other work space allocation techniques the gajw instruction exchanges the contents of wptr and areg , allowing work spaces to be allocated dynamically, and allowing dynamic switching between existing work spaces. if a process work space holds a pointer to a new work space, then the following code changes to the new work space and stores a pointer to the old work space. ldl w new ; gajw; stl w old; the old work space can be restored by ldl w old ; gajw; in addition, the old work space can be accessed from the new work space, using ldl w old ; ldnl x; ldl w old ; stnl x; ldl w old ; ldnlp x; 4.11 peripherals and i/o the peripheral and i/o instructions are listed in table 4.13. 4.11.1 using the io register the io register is a 32-bit register used for simple bit control of devices outside the core. the bits of the register are directly mapped to external connections on the st20- c1 core. the connections to and from the io register may be to on-chip or external peripherals depending on the particular chip design. the bits of the io register are defined in table 3.3. some bits at the most significant end of each half word may be reserved for the system in some st20 variants; see the data sheet for the variant. setting an output bit will cause the corresponding connection to be driven high, and clearing the bit will drive the connection low. similarly any input or output bit may be tested for the state of the connection; if the connection is high the bit will be set and if the connection is low the bit will be clear. the instruction io sets and clears bits of the io register and loads a copy of the initial io register. a bit in the bottom half-word may be set in the io register by: ldc 0; ldc bit_number; bitmask; io; a bit in the bottom half-word may be cleared in the io register by: ldc bit_number; bitmask; ldc 0; io; mnemonic name io input / output bitmask bit mask ldtdesc load task descriptor stop stop process table 4.13 peripheral and i/o instructions
53/205 4 using ST20-C1 instructions ? any bit may be read from the io register by: ldc 0; dup; io; ldc bit_number; bitld; the io register is global and is not changed or saved by a context switch. if more than one process accesses the io register then it may need to be protected by a sema- phore. on reset the io register is set to all zeros. 4.11.2 memory-mapped peripherals on-chip peripherals may have memory-mapped registers in the address space . access to these registers is performed in the same way as accessing memory. if a peripheral has a block of word-aligned registers with base address peripheral then a register with word offset register may be read by: ld peripheral; ldnl register; and value may be written to the register by: ld value; ld peripheral; stnl register; 4.11.3 channel-type peripherals some peripherals, for example peripherals using dma (direct memory access), may use a channel-type control model. this section describes how to use such periph- erals, which use a micro-interrupt to notify the cpu that an assigned job is completed. this type of peripheral works best with a multi-tasking program, so that the cpu has other processes to execute while the peripheral is busy. however, if multi-tasking is not otherwise required, then an interrupt model can be used. multi-tasking is described in chapter 7 and interrupts and the exception vector table are described in chapter 6. multi-tasking the principle of using the channel model with multi-tasking is that the cpu tells the peripheral to start a job and then deschedules the current process. the job might be peripheral input/output or dma transfer. this allows the cpu to continue executing other processes while the job is in progress. when the peripheral completes the job it signals to the cpu, which reschedules the process. to enable this to happen, the task descriptor of a user process can be entered into the exception vector table. this entry is called the peripheral channel. the peripheral signals a micro-interrupt, which interrupts the cpu with the exception level associated with the user process. the cpu recognizes that the exception vector table entry is a user process because bit zero is userprocesstype , and either adds the process to the end of the scheduling queue or takes a schedule exception trap if installed. the scheduling exception trap allows a scheduling kernel to control the rescheduling of the process. in more detail, the steps to perform a job using this model are:
4.11 peripherals and i/o 54/205 ? 1 the cpu saves the task descriptor of the current process in the exception vector table at the exception level for the peripheral. 2 the cpu tells the peripheral the number of bytes to be read or written, the address of the start of the data or input buffer. 3 the cpu signals to the peripheral that the job can start. 4 the cpu deschedules the process, using the stop instruction, to wait for the peripheral to complete the job. 5 the cpu executes other processes while the peripheral performs the job. 6 the peripheral completes the job and sends a micro-interrupt to the cpu, with the exception level. 7 the cpu reads the exception vector table and recognises the entry as a user process. the process is added to the back of the scheduling queue, or if the schedule execution trap is enabled then the trap is taken. the code to execute steps 3 to 4 must not be interrupted, since otherwise the periph- eral job may be completed before the process is descheduled by a stop instruction, which may crash the processor. interrupts may be temporarily disabled by clearing the local_interrupt_enable bit of the status register, which is set automatically when the process is descheduled. steps 5 to 7 happen automatically and need no coding. the code to drive the peripheral will depend on the peripheral and the interface to it. typically the parameters (e.g. the byte count and the buffer address) would be written to memory mapped registers and then a further write would be needed to start the peripheral job. the code to perform a dma to transmit param_count bytes to or from param_buffer using exception level except_level where the dma registers periph_count , periph_buffer and periph_start are in a block at peripheral would be similar to the following: ldtdesc; ld exceptionbase; stnl except_level; ld param_count; ld peripheral; stnl periph_count; rev; ld param_buffer; stnl periph_buffer; ldc local_interrupt_enable; bitmask; statusclr; rot; ldc start_value; arot; stnl periph_start; stop; the process will resume at the next instruction after the stop when the peripheral job is complete. single tasking for programs which are not multi-tasking, it is not desirable to deschedule the program while the peripheral is busy. the main program should continue with other jobs while the peripheral is busy. an interrupt handler can be written to signal to the main program that the peripheral job is complete. the descriptor of the interrupt handler exception control block is placed in the exception vector table. the descriptor
55/205 4 using ST20-C1 instructions ? is the address of the control block ored with the type flag exceptionprocesstype in bit 0. the code to perform a dma to transmit param_count bytes to or from param_buffer using exception level except_level where the dma registers periph_count , periph_buffer and periph_start are in a block at peripheral and the interrupt handler is at except_control_block would be similar to the following: ld except_control_block; ldc exceptionprocesstype; or; ld exceptionbase; stnl except_level; ld param_count; ld peripheral; stnl periph_count; ld param_buffer; arot; stnl periph_buffer; ldc start_value; arot; stnl periph_start; when the interrupt handler starts execution the peripheral job will be complete. 4.12 status register the status register may be manipulated using the instructions listed in table 4.14. in each of these instructions, areg holds a bit mask. statusclr copies the initial status register into the areg and clears the bits of the status register that are set in the initial areg . for example, to clear the bit bit_number : ldc bit_number; bitmask; statusclr statusset is similar, but sets the bits of the status register that are set in the initial areg . statustst returns in the areg the status bits masked by the initial areg . the breg and creg are unaffected. the status register is described in section 3.3.2. mnemonic name statusclr clear bits in status register statusset set bits in status register statustst test status register table 4.14 semaphore instructions
5.1 data formats 56/205 ? 5 multiply accumulate this section describes the multiply-accumulate instructions and their use. all these instructions are described in the context of their intended use. instructions for general use (arithmetic, loading, storing etc.) are described in chapter 4. instructions for exceptions are described in chapter 6 and multi-tasking instructions are described in chapter 7. the architecture of the ST20-C1, including the registers and memory arrangement, is described in chapter 3. multiply accumulate operations are provided by the signal processing instructions listed in table 5.1. 5.1 data formats a signed fractional number of n bits is described as x.y , where x + y = n . this means the number is made up from x bits before the binary point, an implied binary point, and y fractional bits. more details of the data formats are given in section 5.7. 5.2 mac and umac mac and umac are general purpose multiply accumulate instructions, multiplying two 32-bit values and adding them to a 32-bit unsigned initial accumulator, giving a 64-bit accumulator. mac treats the multiplicands as signed and umac treats them as unsigned. initially areg and breg hold the values to be multiplied and creg holds the initial accumulator. on completion, areg is the least significant word of the result accumulator, breg the most significant and creg holds a copy of the initial areg . 5.3 short multiply accumulate loop the smacloop instruction performs a multiply-accumulate operation on two vectors of 16-bit values held in memory. it takes an initial accumulator value and two pointers, one to each of two data vectors. ? the x vector of data values is normally considered to reside within a circular buffer of programmable size, but this can be turned off. when data fetches reach the end of this buffer, the pointer wraps-around back to the start of the buffer and continues. the x vector must be word aligned. ? the y vector of coefficients is always in a flat address space , and never wraps around. the y vector must be half-word aligned. mnemonic name mac multiply accumulate umac unsigned multiply accumulate smacinit initialize short multiply accumulate loop smacloop short multiply accumulate loop biquad biquad iir filter step table 5.1 multiply accumulate instructions
57/205 5 multiply accumulate ? the data items from each vector are read from memory in turn and the products formed between corresponding pairs from the two vectors. each of these products is added into the running accumulator value. the instruction completes with 3 values in the stack - the final accum ulator value and the two updated data pointers. four control values are held in the status register, as shown in table 5.2. these values are initialized by the smacinit instruction. the smacinit instruction takes a packed control word in areg , extracts the control fields and loads these into the status register. for smacinit , areg is organized as shown in table 5.3. these status register values are global and are not saved when a process is times- liced or descheduled. if more than one process is performing short multiply accumu- late loops then the values should be reloaded by the process code using smacinit after each timeslice and stop instruction. 5.3.1 x buffer size the x vector buffer size is determined by the mac_buffer control field, which may take the values 0 to 7. when mac_buffer is 0, then no address wrapping takes place, i.e. the buffer is assumed to be of infinite size. otherwise, the buffer size is 2 mac_buffer+2 , as shown in table 5.3. the x buffer must be aligned to a multiple of its own size, so a buffer of n bytes must start at an address whose value is a multiple of n bytes. 5.3.2 number of steps the mac_count control field in the status register deter mines the number of multiply- accumulate steps for smacloop . this is an unsigned 8-bit integer. the value zero signifies 256 steps; otherwise the v alue of mac_count is the number of steps. field size meaning mac_count 8 bits the number of steps (from 1 to 256 items). mac_buffer 3 bits the size code for the data buffer within which the data vector lies. mac_scale 2 bits shift control for scaling coefficient v alues. mac_mode 1 bit accumulator format - 0 indicates 16-bit (short) and 1 indicates 32-bit (long) value. table 5.2 smacloop status register fields field size least significant bit most significant bit mac_count 8 bits 0 7 mac_buffer 3 bits 8 10 mac_scale 2 bits 11 12 mac_mode 1 bit 13 13 table 5.3 smacinit areg format
5.4 biquad iir filter 58/205 ? 5.3.3 scaling scaling of the input data in the x vector is controlled by the mac_scale field of the status register, as described in section 5.6. 5.3.4 accumulator format mode smacloop supports two data formats for the initial and final accum ulator value. if mac_mode is 0 then q15 (sign extended to 32 bits) is used, and the mode is said to be shortmode .if mac_mode is 1 then q31 is used, and the mode is said to be longmode . 5.4 biquad iir filter the biquad instruction performs a fixed sequence of 5 multiply-accumulates. figure 5.1 shows an example using q14 format. the parameters to the instruction are pointers to three vectors of 16-bit values: ? an x input data vector, ? a y results vector and ? a coefficient v ector c. this vector must be word-aligned. biquad calculates the next item in the y vector according to the following formula, and writes this to memory, incrementing the x and y pointers by two bytes: y[2] = x[0].c[0] + x[1].c[1] + x[2].c[2] + y[0].c[3] + y[1].c[4] the x and y vectors must be either both word-aligned or neither word-aligned. the c pointer is left unchanged. this allows successive biquad instructions to be executed back-to-back to generate a set of filter outputs with no additional overhead. biquad scales the x input data according to the mac_scale field of the status register, as described in section 5.6. the mac_scale field ma y be set using smacinit ,as described in section 5.3. mac_buffer buffer size (data items) buffer size (bytes) 0 infinite infinite 14 8 28 16 316 32 432 64 5 64 128 6 128 256 7 256 512 table 5.4 mac_buffer coding
59/205 5 multiply accumulate ? 5.5 data vectors both biquad and smacloop operate on arrays of 16-bit values, packed two per word. this allows the ST20-C1 to read two values per cycle from memory which is funda- mental to the high performance of the multiply-accumulate instructions. in all cases, data values must be half-word aligned. figure 5.1 ST20-C1 biquad instruction example: q15 = q15 q14 5.6 scaling the biquad and smacloop operations are performed with an oversize accumulator of 48 bits. the accumulator value is always sign-extended to the full width of the accu- mulator. during a multiply-accumulate sequence the value in the accumulator may temporarily go outside the representable range of the final result, but can never overflow the accu- mulator for a single biquad or smacloop . 5.6.1 accumulator scaling the user-visible accumulator is either in longmode (q31) or shortmode (q15). for smacloop , the mode is defined b y the mac_mode status register field. biquad only supports shortmode . pre-scaling converts the user-visible accumulator to an internal format accumulator, as shown in figure 5.2. the inverse operation is post-scaling which is converting an q14 z -1 input z -1 << 9 >> 23 z -1 z -1 output coefficients: 0, l4, l8, l9 accumulator: r23 shifts q14 q14 q14 q14 q15 q15 c[0] c[1] c[2 ] c[4] c[3] x[0] x[1] x[2] y[1] y[0] y[2] << 9 << 9 << 9 << 9 << 22 1
5.6 scaling 60/205 ? internal format accumulator to a user-visible accumulator. figure 5.2 accumulator scaling the accumulator is left-shifted 8 bits so that the assumed binary point is moved from below bit 30 to below bit 38. the accumulator value is saturated from bit 38 upwards. at the end of the multiply-accumulate sequence the accumulator value is shifted down (right) by an extra 8 bits to compensate for the left shift of 8 on coefficient inputs. 5.6.2 coefficient scaling the standard data format for data and coefficients is 1.15 (q15). the product of two 1.15 numbers is 2.30. the coefficient value for each multiply-accumulate operation is pre-scaled before being fed into the multiplier. the shift distances are controlled by the mac_scale field: of the status register, as shown in table 5.5. the standard behavior for 1.15 (q15) values is to shift the coefficients b y 8 places, using mac_scale set to 2, which exactly compensates the extra right shift of 8 on the mac_scale coefficient shift 00 1 left 4 2 left 8 3 left 9 table 5.5 mac_scale values shortmode and biquad longmode 1 1 user-visible accumulator internal accumulator 0 47 38 0 15 internal accumulator 0 47 38 0 31 user-visible accumulator implied binary point bit initially set for rounding
61/205 5 multiply accumulate ? final accum ulator. this is shown in figure 5.3. figure 5.3 coefficient scaling with mac_mode set to 2 shifting the coefficient b y 1 extra place (i.e. 9 places) is used to normalize a 2.14 (q14) coefficient to the correct position for the binary point. this is shown in figure 5.4. figure 5.4 coefficient scaling with mac_mode set to 3 y data value 0 15 add to internal accumulator 0 47 39 0 23 x data value 0 15 << 8 8 8 y data value 0 15 add to internal accumulator 0 47 40 0 24 x data value 0 15 << 9 9 9
5.6 scaling 62/205 ? under shifting (by less than 8) is used for magnitude reduction (most suitable for smacloop ) by 4 bits (x16) using mac_scale =1 or 8 bits (x256) using mac_scale =0. under-shifting by 4 bits is shown in figure 5.5, and by 8 bits in figure 5.6. figure 5.5 coefficient scaling with mac_mode set to 1 figure 5.6 coefficient scaling with mac_mode set to 0 y data value 0 15 add to internal accumulator 0 47 35 0 23 x data value 0 15 << 4 4 4 y data value 0 15 add to internal accumulator 0 47 31 0 23 x data value 0 15
63/205 5 multiply accumulate ? 5.6.3 pre-scaling and rounding - smacloop the initial accumulator value must be loaded into the accumulator for the start of the smacloop instruction. the initial accumulator is either in q31 format ( longmode ), or q15 format ( shortmode ) and is handled accordingly. in longmode , ? left shift by 7 places (right 1 + left 8) ? sign extend from bit 38 to the most significant bit ? set bit 6 = 1 (for rounding) in shortmode , ? left shift by 23 places (left 15 + left 8) ? sign extend from bit 38 to the most significant bit ? set bit 22 = 1 (for rounding) note that rounding is achieved by adding half of the least significant bit to the initial value, which by associativity is equivalent to adding it to the final value. 5.6.4 pre-scaling and rounding - biquad the biquad instruction starts with an empty accumulator. since the result is always q15 (equivalent to shortmode ), rounding is achieved by loading the accumulator with 2 22 (which is half of the least significant bit of the result). 5.6.5 post-scaling and saturation - smacloop at the end of a smacloop instruction the final accum ulator value is saturated and scaled to the appropriate format, according to mac_mode . if either the overflow or underflow bits in the status register are set, then the final value is set to the appropriate exceptional value from table 5.6. note that this does not involve testing the accumulator value, which is considered to be invalid if either of these status register bits are set. otherwise, when the status register reports no overflow or underflow, bits 38 to 47 inclusive of the accumulator are tested for mutual equality. if they are all the same, the accumulator value is well-formed and post-scaling is applied to produce the final accu- mulator value. in longmode , ? arithmetic right shift by 7 places(left 1 + right 8) ? truncate to low 32 bits in shortmode , ? arithmetic right shift by 23 places (right 15 + right 8) ? truncate to low 32 bits
5.6 scaling 64/205 ? however if the bits are not all equal, then an error has occurred. if the most significant bit (bit 47) is zero then the overall result is positive, so the error is overflow. if the most significant bit is 1 then the o verall result is negative, so the error is underflow. the appropriate status register bit ( overflow or underflow ) is set accordingly, and the final value is taken from table 5.6. 5.6.6 post-scaling and saturation - biquad the result of a biquad is always short (16-bits). the saturation test is from bit 38 upwards, and the overflow / underflo w flags are set as required. note the initial value of the overflow / underflo w flags is not taken into account. if a saturation error occurs, the appropriate shortmode value from table 5.6 is used. if no error occurs, the scaling is: ? arithmetic right shift by 23 places ? truncate to low 32 bits 5.6.7 error: load exceptional value there are four exceptional values based on whether the result is to be delivered as a shortmode (q15) or longmode (q31) value, and whether the error was overflow or underflow: note that in all cases the final v alue is placed in a 32-bit register ( areg ). 5.6.8 performance and interrupts biquad the biquad instruction takes 11 cycles to execute, assuming single cycle memory accesses. the ST20-C1 cannot be interrupted during this period. smacloop a smacloop of n steps takes n+4 cycles to complete, assuming single cycle memory accesses. the ST20-C1 cannot be interrupted during this period, which may be up to about 8 microseconds (for single cycle memory and an operating frequency of 33 mhz). the user may split a long multiply accumulate into a set of shorter ones passing the inter- mediate accumulator value from one to the next. this will reduce interrupt latency, but loses some numerical accuracy in that within a single smacloop intermediate values are held to 48 bits of precision, while values passed from one smacloop to another have at most 30 bits of precision (and are saturated). mac_mode overflo w underflo w shortmode 00007fff ffff8000 longmode 7fffffff 80000000 table 5.6 exceptional values
65/205 5 multiply accumulate ? 5.7 data formats this section gives details of the data formats used by the smacloop and biquad instructions. a signed fractional number of n bits is characterized as x.y, where x+y=n. this means the number is made up from x bits before the binary point, an implied binary point, and y fractional bits. some examples are listed in table 5.7. 5.7.1 range a value n in x.y format has a range -2 x-1 n < 2 x-1 . for example, a value in the format 1.15 has range -1 n < 1, and the format 2.14 has range -2 n <2. 5.7.2 multiplication the characteristic of the product of two fractional values is given by: a.b * c.d = a+c.b+d 5.7.3 supported formats table 5.8 shows the data formats for multiply-accumulate operations supported by the ST20-C1. note that a q15 value may be (optimally) stored in a 16-bit field, or a wider (>16-bit) field with redundant sign bits. the two storage methods are described below. 5.7.4 q15 in 16 bits q15 format is a 16-bit signed fractional value in the range -1 n < 1. the value is stored in two's-complement form with a sign bit (bit 15), an implied binary point between bits 15 and 14, and 15 significant fractional bits (bit 14 to bit 0). total bits range format short name 32 -1 n < 1 1.31 q31 16 -1 n<1 1.15 q15 16 -2 n < 2 2.14 q14 table 5.7 example data formats description name format signed 16-bit fractional q14 14 significant fr actional bits signed 16-bit fractional q15 15 significant fr actional bits signed 16-bit fractional q31 31 significant fr actional bits table 5.8 supported multiply accumulate data formats
5.7 data formats 66/205 ? a q15 value in a 16-bit field is organiz ed as shown in figure 5.7. figure 5.7 q15 data format (16-bits) the minimum and maximum representable values are as shown in table 5.9. 5.7.5 q15 in an oversized field when a q15 value is stored in an oversized field, e .g.a 32-bit register, the significant bits are placed at the least significant end of the field, and the v alue is sign-extended to the width of the whole field. the value still has the same range (-1 n < 1) and the same number of significant bits. a q15 value in a 32-bit field is organiz ed as shown in figure 5.8. figure 5.8 q15 data format (32-bits) the minimum and maximum representable values are as shown in table 5.10. hex value decimal value minimum 8000 -1 maximum 7fff +0.9999 table 5.9 q15 limiting values 2 -1 -(2 0 )2 -2 2 -3 2 -14 2 -15 binary point sign bit 15 14 13 12 0 1 bit position most significant least significant -(2 0 ) -(2 0 ) -(2 0 ) -(2 0 ) -(2 0 )2 -1 2 -14 2 -13 2 -15 binary point sign bit 31 30 29 16 15 14 0 1 2 bit position most significant least significant basic q15 value sign extended
67/205 5 multiply accumulate ? memory access a q15 stored in memory may be loaded to areg with a lsxinc instruction which will automatically sign-extend the value. similarly a q15 may be written to memory with a ssinc instruction (which will discard the top 16 bits). saturation a well-formed q15 value is sign extended to the width of the field, and so bits 15 to 31 inclusive will all be identical. conversely, if the bits from 15 to 31 inclusive are not all identical, then the value is not well-formed. it has either overflowed (if b31=0, so positive) or underflo wed (if bit31=1, so negative). a q15 value in areg may be saturated with the sequence: ldc 00007fff; order; ldc ffff8000; order; rev; 5.7.6 q31 format q31 format is a 32-bit signed fractional value in the range -1 n < 1. the value is stored in two's-complement form with a sign bit (bit 31), an implied binary point between bits 31 and 30, and 31 significant fractional bits (bit 30 to bit 0). a q31 value in a 32-bit field is organiz ed as shown in figure 5.9. figure 5.9 q31 data format the minimum and maximum representable values are as shown in table 5.11. hex value decimal value minimum ffff8000 -1 maximum 00007fff +0.9999 table 5.10 q15 limiting values 2 -1 -(2 0 )2 -2 2 -4 2 -3 2 -5 2 -30 2 -29 2 -31 binary point sign bit 31 30 29 28 27 26 0 1 2 bit position most significant least significant
5.7 data formats 68/205 ? hex value decimal value minimum 80000000 -1 maximum 7fffffff +0.99999999 table 5.11 q31 limiting values
69/205 5 multiply accumulate ?
70/205 ? 6 exceptions this chapter describes exceptions and how to use them. the architecture of the ST20-C1, including the registers and memory arrangement, are described in chapter 3. a full list of constants and data structures is given in appendix a. an exception is an exceptional event detected by the ST20-C1 core, which causes a context switch from the normal flow of an executing program. the event triggering the exception may be generated by software inside the core, in which case it is called a trap. otherwise, the event may be a hardware signal from outside the core, in which case it is called an interrupt, except that the interrupt may attempt to perform a sched- uling action, which may cause a trap. when an exception occurs the cpu changes context to an exception handler , which is a section of code only executed when an exception occurs. the process state registers ( areg , breg , creg , iptr , wptr , status and tdesc ) are saved while the exception handler is running, and restored when it returns. exception handlers for traps are called trap handlers and exception handlers for interrupts are called interrupt handlers . normal processes which are not exception handlers are known as user processes . the exception handler is a transient process. each exception handler starts execution with a standard initial state, runs to completion and terminates with an empty work- space. when the triggering event occurs again, the handler is restarted from its standard initial state and again runs to completion and terminates. exception handlers may be nested to arbitrary depth, but they are not re-entrant, so care should be taken to ensure that the exception which caused the handler to run cannot occur while the handler is running, trapped or interrupted. the nesting of exceptions is illustrated in figure 6.1. figure 6.1 nested exceptions user process user process exception 1 taken - state of user process saved exception 2 taken - state of exception 1 saved exception 2 returns - state of exception 1 restored exception 1 returns - state of user process restored exception 1 executing exception 1 executing exception 2 executing
71/205 6 exceptions ? exception handler code is completed by executing the eret instruction, which restores the state of the interrupted or trapped process. when an interrupt handler executes eret , it also signals to the interrupt controller that the interrupt has completed. this allows the interrupt handler to start a lower priority waiting interrupt if required. the exception instructions are listed in table 6.1. 6.1 exception levels all exception handlers are identified by an integer called the exception level . exception levels 0 to highestexception (255) are available for user-defined exceptions, while system exceptions have negative levels, as defined in table 6.2. any exception may be triggered from software with the ecall instruction. user-defined exceptions can be interrupt handlers, user processes waiting for dma peripherals or trap handlers used as system calls by executing ecall . system exceptions are traps which may be triggered automatically when the cpu is in certain states. they are intended mainly for operating system kernels to trap sched- uling events and for debuggers to trap breakpoints. the circumstances in which each system trap is taken are as follows: ? el_breakpoint_trap this trap is taken when either a breakpoint instruction is executed or a diag- nostic controller (dcu) signals to the cpu requesting a breakpoint. if the trap is null then the process continues. this trap is used by debuggers. mnemonic name ecall exception call eret exception return breakpoint breakpoint table 6.1 exception instructions exception level name circumstances when taken if not null 0 - 255 - interrupt, system call, dma user process. -1 el_breakpoint_trap breakpoint instruction executed or dcu break- point request. -2 el_illegal_instr_trap illegal op-code encountered. -3 el_idle_trap cpu becomes idle. -4 el_schedule_exception_trap schedule a user process as an exception. -5 el_run_trap execute a run instruction. -6 el_stop_trap execute a stop instruction. -7 el_timeslice_trap take a timeslice. table 6.2 exception levels
6.2 exception vector table 72/205 ? ? el_illegal_instr_trap this trap is taken when the cpu encounters an instruction with an illegal op- code. if the trap is null then the instruction is treated as a nop . ? el_idle_trap this trap is taken when the cpu becomes idle, i.e. the current process exe- cutes a stop when there are no active processes waiting for cpu time, or a timeslice is trapped or interrupted so that there are no active processes waiting when the cpu attempts to start the next process. if the trap is null then the cpu waits for an interrupt or for a process to be scheduled. this trap is used by software scheduling kernels. ? el_schedule_exception_trap this trap is taken when an interrupt is received from a peripheral and the exception level is assigned to a user process, which will generally be desched- uled waiting for the peripheral to complete a job. if the trap is null then the user process is queued. this trap is used by software scheduling kernels. ? el_run_trap this trap is taken when the run instruction is executed. if the trap is null then the cpu adds the process to the back of the scheduling queue. this trap is used by software scheduling kernels. ? el_stop_trap this trap is taken when the stop instruction is executed. if the trap is null then the current process is descheduled and the cpu starts executing the process on the front of the scheduling queue, or goes idle if there is none. this trap is used by software scheduling kernels. ? el_timeslice_trap this trap is taken when a timeslice is due and enabled and the timeslice instruction is executed. if the trap is null then the current process is timesliced, i.e. placed on the back of the scheduling queue. this trap is used by software scheduling kernels. scheduling and timeslices are discussed in chapter 7. using user processes as exceptions to handle peripherals is described in section 4.11. 6.2 exception vector table the exception vector table maps each exception level to a user process or exception. the base of the exception vector table is at the fixed address exceptionbase (#80000040) in on-chip memory, and the exception level is the word offset from the exceptionbase to the vector. thus the exception level is used as an index into the exception vector table. the address of the user process or exception is always word aligned, and so has bits 0 and 1 set to zero. the entry in the exception vector table is a descriptor , which consists of the address of the user process or exception ored with a type. the type is
73/205 6 exceptions ? bit 0 of the descriptor, and so can be either exceptionprocesstype (which has the value 1) or userprocesstype (which has the value 0). the type allows each exception level to be assigned to one of the following: ? an exception handler. the entry for an exception handler is the address of the exception control block (as described in section 6.3) bitwise ored with exceptionprocesstype to indicate an exception. ? a user process waiting for a peripheral (as described in section 4.11).the entry for a user process is the task descriptor (i.e. the address of the process control block) bitwise ored with userprocesstype to indicate a user process. ? the null entry notprocess . the cpu treats null entries as disabled exceptions. when the exception is triggered, the cpu looks in the table entry for the requested exception level. if the value in the table is notprocess then no exception or trap is taken and the cpu continues with the default behavior. otherwise, if bit 0 is userprocesstype then the address part of the value is assumed to be a valid task descriptor of a process. if bit 0 is exceptionprocesstype , then the address part is assumed to be a pointer to a valid exception control block. using user processes as exceptions to handle peripherals is described in section 4.11. the rest of this chapter refers only to exceptions. typically a separate descriptor is used for each interrupt level and system call, so that this scheme provides a system of vectored interrupts and system calls. the exception handler is then executed, and can itself be interrupted or trapped. 6.3 exception control block and the saved state when an exception is taken, the state is saved in the exception control block. the evaluation stack, status register, iptr , wptr and tdesc are automatically saved on taking the exception and restored on returning. this is done to enable any exception handler to have direct access to the state of the underlying process and is required for some software scheduler implementations. the constants in table 6.3 define the locations in the control block. word offset name purpose 7 ex.handleriptr exception handler instruction pointer. 6 ex.interptdstatus interrupted or trapped process status register. 5 ex.interptdtdesc interrupted or trapped process task descriptor. 4 ex.interptdiptr interrupted or trapped process instruction pointer. 3 ex.interptdwptr interrupted or trapped process workspace pointer. 2 ex.interptdcreg interrupted or trapped process creg . 1 ex.interptdbreg interrupted or trapped process breg . 0 ex.interptdareg interrupted or trapped process areg . table 6.3 exception control block
6.4 initial exception handler state 74/205 ? the control block is at the initial wptr for the exception handler, so the locations are word offsets from the initial wptr of the exception handler. the initial wptr is the address of the exception control block which is the address part of the entry in the exception vector table. 6.4 initial exception handler state when the exception handler starts, wptr is set to the address of the exception control block. the work space of the exception handler is normally below the control block, so like a function or procedure call, one of the first actions of the exception handler code is to adjust the wptr downwards to create space for local variables using ajw . the wptr must be adjusted back up again before the handler returns. the initial iptr of the exception handler is the value loaded from ex.handleriptr in the exception control block. the state of the interrupted or trapped process is saved in the exception control block. if the exception is an idle trap then the saved state is the state of the last descheduled process. initially the status register is set to the values shown in table 6.4. if the exception handler is interrupting a user process, then the address of the exception control block (i.e. the user process state) is left in tdesc . if necessary, the exception handler can save this address. if a sequence of nested interrupts has field or bit value mac_count as in the interrupted or trapped process. mac_buffer as in the interrupted or trapped process. mac_scale as in the interrupted or trapped process. mac_mode as in the interrupted or trapped process. global_interrupt_enable false if exception is a trap, otherwise preserved. local_interrupt_enable as in the interrupted or trapped process. overflo w false. underflo w false. carry false. user_mode false. interrupt_mode true if any interrupts are running, false otherwise. trap_mode true if exception is a trap, false otherwise. sleep false. reserved undefined. start_next_task false. timeslice_enable false. timeslice_count as in the interrupted or trapped process. table 6.4 exception handler initial status register
75/205 6 exceptions ? occurred then this is the only way that the nested interrupts can identify the state of the user process. if the exception is a schedule_exception trap then the trap handler also needs to know the process due to be scheduled. the descriptor of the process (as held in the exception vector table) is saved at savedtaskdescriptor near the bottom of the address space. 6.5 restrictions on exception handlers exception handlers cannot be queued, so they must not deschedule. this means that the following are not permitted inside exception handlers: ? the stop instruction; ? the timeslice instruction. exception handlers may be nested to arbitrary depth, but they are not re-entrant, so care should be taken to ensure that the exception which caused the handler to run cannot occur while the handler is running, trapped or interrupted. 6.6 interrupts all interrupts, whether from on-chip peripherals or external pins, are routed through an interrupt controller, which is normally an on-chip peripheral. the interrupt controller is responsible for arbitration between multiple interrupt signals. the design of the interrupt controller varies between st20 variants. typically, interrupt priorities are managed by the interrupt controller, which will usually track the priority of the highest level task currently executed by the core, and will interrupt the ST20-C1 again if a higher priority interrupt occurs. when an interrupt is requested by the interrupt controller, the ST20-C1 always changes context to the appropriate interrupt handler. an interrupt request is accompa- nied by an identifier for the interrupt handler, which is the exception level. the st20- c1 scheduler uses the exception level from the interrupt controller to start the appro- priate interrupt handler. the cpu also sets the interrupt_mode bit in the status register and clears the trap_mode and user_mode bits. the interrupt_mode bit indicates that an interrupt handler is running, though it may have been trapped. when the interrupt handler executes the eret instruction, the cpu signals to the interrupt controller that the handler has returned. this allows the interrupt controller to keep track of which interrupt handlers are running, so that it can start a low priority waiting interrupt when a higher priority handler completes. if the interrupt controller requests an interrupt level which has a null interrupt handler then the cpu signals to the controller that the interrupt has completed.
6.7 traps 76/205 ? 6.7 traps the ST20-C1 has a system of traps which act as software generated interrupts. any level of exception can be called as a user exception using ecall . this mechanism can be used for system calls to an operating system. in addition some special exception levels are reserved for system use to provide for the trapping of breakpoints, scheduling events, illegal operations and the machine becoming idle. the reserved `system' exception levels are described in section 6.1. if a system trap event occurs or a trap is called at an exception level which has a null trap handler then the cpu ignores the trap and continues. when a non-null trap handler is started, the trap_mode bit of the status register is set and the user_mode bit is cleared. the interrupt_mode bit is not altered. the trap_mode bit indicates that a trap handler is currently executing, so it is cleared if the trap handler is interrupted. 6.8 setting up the exception handler to create an exception handler, an exception work space area must be created, with enough space for the exception handler's stack and 8 words at the top of the work space for the exception control block, as defined in table 6.3. for minimum interrupt latency, interrupt handler control blocks should be in fast memory, preferably on-chip. the normal work space and control block of an exception handler is shown in figure 6.2. in the control block, ex.handleriptr must be initialized to point to the entry point of the exception handler code. figure 6.2 exception handler ex.handleriptr pointer or 1 exception handler code entry point interrupted or trapped state work space exception vector table exception level (7 words) (word offset) exceptionbase exception handler initial exception handler wptr
77/205 6 exceptions ? the code of the exception handler may access or modify the state of the interrupted or trapped process. the state of the interrupted or trapped process is stored in the exception control block, which is located at the initial wptr of the exception handler. an exception handler must use eret to return to the interrupted or trapped process. 6.8.1 enabling and disabling exceptions when the exception handler has been created and initialized, the exception can be enabled. the address of the exception handler control block, ored with 1 to set the exception type bit, must be written in the exception vector table at the level for the exception. to write an entry control_block with type exceptionprocesstype in the exception vector table, the following code may be used: ld control_block; ldc exceptionprocesstype; or; ld exceptionbase; stnl exception_level; for interrupts, both the global_interrupt_enable and local_interrupt_enable bits in the status register must be set. in addition the interrupt controller may need to be initial- ized, including any interrupt enable bits and masks. a trap can be disabled by writing notprocess into the exception vector table. interrupts can be disabled in four ways: 1 clearing the status register bit global_interrupt_enable disables all interrupts until the bit is set by an explicit write to the status register. 2 clearing the status register bit local_interrupt_enable disables all interrupts until the current process is descheduled. 3 a single exception level can be disabled by writing notprocess into the excep- tion vector table. 4 the interrupt controller will generally have a means of disabling interrupts indi- vidually or globally by writing to interrupt controller registers.
7.1 processes 78/205 ? 7 multi-tasking this chapter describes the features of the ST20-C1 core provided to support multi- tasking, and how to use them. the architecture of the ST20-C1, including the registers and memory arrangement, are described in chapter 3. interrupts and traps are described in chapter 6. a full list of constants and data structures is given in appendix a. support is provided in the instruction set for timeslicing, scheduling processes and manipulating queues of processes. 7.1 processes a process (also known as a task or thread) is an independent unit of software with a single thread of control, i.e. a sequential algorithm. any number of processes may be run. a process which has been started but not terminated may be in one of several different states: ? executing on the cpu; ? interrupted or trapped by an exception; ? inactive , i.e. waiting for a peripheral or semaphore signal; ? waiting for cpu time. a process that is not inactive is said to be active. a process that is not executing or interrupted is said to be descheduled. the states and main transitions are shown in figure 7.1. the scheduling transitions can be trapped so that a software scheduling kernel can modify the transitions and so change the scheduling behavior, for example by providing a system of process priorities. figure 7.1 process states and main transitions waiting for cpu time executing interrupted inactive descheduled processes active processes interrupt or trap return event terminate run terminated not started descheduled timeslice or trapped
79/205 7 multi-tasking ? a process state is held in memory and the cpu registers. sufficient of the register state must be saved when the process is interrupted or a context switch occurs, so that the process can be reloaded and continue execution at a later time. the register state consists of: ? the instruction pointer register; ? the work space pointer register; ? the task descriptor register; ? the evaluation stack registers; ? the status register. in order to save memory space and context switch time, processes are only desched- uled when the evaluation stack and status register are empty. this is achieved by only allowing processes to deschedule at certain instructions, called deschedule instruc- tions, after which the final values in the evaluation stack are undefined and the status register is reset to a default value. the deschedule instructions are stop and timeslice . table 7.2 lists the multi-tasking instructions. 7.2 descheduled processes if the process is waiting for a peripheral or a semaphore or descheduled by a timeslice then the evaluation stack is not saved. the instruction pointer and wptr are saved in the process descriptor block . the task descriptor is the address of the process descriptor block. it therefore identifies the waiting process and points to its saved state. the task descriptor is a fixed address for each process, unlike the wptr which changes as the code executes. when the process is running, the task descriptor is held in the tdesc register. mnemonic name run run process stop stop process timeslice timeslice ldtdesc load task descriptor enqueue enqueue a process dequeue dequeue a process table 7.2 multi-tasking instructions word offset slot name purpose 2 pw.iptr the process saved instruction pointer. 1 pw.wptr the process saved work space pointer. 0 pw.link the link to the next process in the queue. table 7.1 process descriptor block
7.3 queues 80/205 ? the structure of the process descriptor block is shown in table 7.1. when the process is not executing, it contains the saved work space pointer and instruction pointer of the process, plus a queue link if the process is in a queue. figure 7.3 illustrates a descheduled process. figure 7.3 a descheduled process 7.3 queues there may be any number of processes waiting for execution, so a queue (i.e. a linked list) of waiting processes is formed, called the scheduling queue . this is an example of a general queue supported by the instruction set for queueing waiting processes. a queue is a linked list of process control blocks, formed by links included in the process control blocks. each link points to the control block of the next process in the queue unless it is the last in the queue, which is undefined. the front and back pointers of a queue are held in a queue control block, as shown in table 7.2. the queue control block is held in memory, and the address of the block is the identifier of the queue . a complete queue is illustrated in figure 7.4. in the case of the scheduling queue, the control block is stored at the reserved address called schedulerqptr (which has the word offset slot name purpose 1 q.bptrloc the back of the queue. 0 q.fptrloc the front of the queue. table 7.2 queue control block process work space (stack) work space pointer link next process task descriptor code local iptr process descriptor block
81/205 7 multi-tasking ? value mostneg ) at the bottom of the memory space. figure 7.4 a process queue 7.4 timeslicing the ST20-C1 includes support for timeslicing. timeslicing is a safeguard in a multi- tasking environment to prevent any one process from taking too much processor time. exception handlers are not timesliced. a timeslicing counter is provided as a field of the status register called the timeslice_count . it is reset to maxtimeslicecount each time a user process is loaded from the scheduling queue into the cpu. the counter is decremented regularly until it reaches 0, and then stays at 0. a timeslice is due when the counter value is 0. if a timeslice instruction is executed when a timeslice is due and timeslicing is enabled then: ? the timeslice trap will be taken if it is installed; ? otherwise the current process will be timesliced, i.e. the current process is placed on the back of the scheduling queue and the process on the front of the scheduling queue is loaded into the cpu for execution. if an exception occurs, the value of the counter is saved with the status register and reloaded when the interrupted or trapped process is restarted. this ensures that a process will be executed for roughly the same time regardless of whether it was inter- rupted or trapped. the timeslice_enable bit of the status register can be used to enable or disable timeslicing. timeslicing is enabled when the bit is set. this bit is preserved when a process is descheduled, so it may be treated as global among user processes. times- licing must not be enabled in exception handlers. front back front back queue control block process descriptor blocks wptr iptr wptr iptr wptr iptr wptr iptr
7.5 inactive processes 82/205 ? 7.5 inactive processes an inactive process is a process that is waiting for some event to occur, such as a process executing a run instruction or a peripheral completing a dma. an inactive process cannot continue even if the cpu is idle. inactive processes are not polled, but should be rescheduled by the event for which they are waiting. a process becomes inactive by saving its own state and then executing the stop instruction. stop automatically saves the iptr and wptr in the process control block. the code should save the tdesc in an appropriate place where the awaited event can find it. the tdesc points to the process control block. the iptr is loaded onto the eval- uation stack using ldpi , the wptr using ldlp 0 and the tdesc using ldtdesc . for example: ldtdesc; ld tdesc_save_address; stnl 0; stop; two mechanisms are provided for rescheduling inactive processes: ? executing the run instruction. this allows other processes to reschedule an inactive process. for example, this is used when semaphore signalling to a waiting process and could be used by other communications, possibly imple- mented by an operating system. ? scheduling an exception. this allows external devices to reschedule an inac- tive process. for example, this is used by dma peripherals to wake a process waiting for the dma to complete. exception scheduling is described in section 4.11. the run instruction takes a task descriptor in areg and adds the process control block to the back of the scheduling queue. for example: ld task_descriptor ; run; inactive processes may need to be queued, for example while waiting for a sema- phore. the semaphore queue handling is incorporated into the signal and wait instruc- tions, but for other queues the instructions enqueue and dequeue are needed. enqueue will add a process to the back of an arbitrary queue, and dequeue will take a process from the front of the queue. 7.6 descheduled process state when a process restarts after an interrupt or trap, the entire state is loaded from the saved state. however, when the process starts or restarts after being descheduled, the cpu makes assumptions about the state of the process, since not all the state was saved. wptr and iptr are set to the values saved in pw.wptr and pw.iptr of the process descriptor block. the status register is set to the values shown in table 7.3. the global interrupt enable and timeslice enable are global status bits, and are carried over from one process to the next when a context switch occurs.
83/205 7 multi-tasking ? 7.7 initializing multi-tasking 7.7.1 initializing the scheduling queue before multi-tasking operations can be performed, the scheduling queue must be initialized. the scheduling queue is described in section 7.3. the queue must be initialized by setting it to empty, which means setting the front pointer to empty: ld mostneg; ld schedulerqptr; stnl q.fptrloc; 7.7.2 creating and starting a process a process consists of code, a work space area, a process control block and the values for the iptr , wptr and tdesc . to create a process, a large enough work space is created, and a process control block of three words. it may be convenient to put all the process control blocks together in one area of memory. for fast context switches and minimal interrupt latency, process control blocks should be in on-chip memory. the entry point for the process code is written into pw.iptr of the process control block. the address of the top of the work space is written into pw.wptr of the process control block, so the process code must adjust the initial wptr down using ajw to create space for local variables. field or bit value mac_count as in previous process. mac_buffer as in previous process. mac_scale as in previous process. mac_mode as in previous process. global_interrupt_enable as in previous process. local_interrupt_enable set. overflo w false. underflo w false. carry false. user_mode true. interrupt_mode false. trap_mode false. sleep false. reserved undefined. start_next_task false. timeslice_enable as in previous process. timeslice_count maxtimeslicecount. table 7.3 restarted process status register
7.8 scheduling kernels 84/205 ? the following code would set up a process control block: ld entry_point; ld control_block; stnl pw.iptr; ld work_space_top; arot; stnl pw.wptr; the process is then inactive, so it can be added to the back of the scheduling queue using run , exactly as in section 7.5. 7.8 scheduling kernels a scheduling kernel can be written to override the default scheduling behavior of the ST20-C1, but still using the very fast micro-code scheduling. the basis of such a scheduler would be trap handlers to trap the system exceptions el_idle_trap , el_run_trap , el_stop_trap , el_timeslice_trap and el_schedule_exception_trap . when these traps are taken, a scheduling event is due or the processor has become idle. the trap replaces the default scheduling action. when the trap handler returns, the cpu will continue with the next instruction. traps are described in chapter 6. additional system calls may be implemented by user-defined trap handlers, called using ecall . 7.9 semaphores semaphores are a mechanism for managing access to shared resources within a multi-tasking environment. the semaphore operations are provided by the instructions listed in table 7.4. the semaphore instructions act on a semaphore control block, defined in table 7.5. each semaphore has a semaphore control block, which implements a linked list of waiting processes and a count of free resources. the count should be initialized to the total number of available resources (usually one), and the front list pointer should be initialized to the empty value notprocess . for fast signalling and minimal interrupt latency, semaphore control blocks should be in fast memory, preferably on-chip. mnemonic name signal signal wait wait stop stop process run run process table 7.4 semaphore instructions word offset slot name purpose 2 s.back the back of the semaphore waiting list. 1 s.front the front of the semaphore waiting list. 0 s.count the unsigned number of extraprocesses that the semaphore will allow to continue running on a wait request. table 7.5 semaphore control block
85/205 7 multi-tasking ? 7.9.1 waiting for a resource a process requesting a resource executes a wait (or p), which is the following code sequence: ld semaphore; wait; cj continue; stop; continue: the wait instruction is executed, with a pointer to the semaphore control block in areg . the action of wait depends on the count in the semaphore control block. if the count is not zero, then a resource is free, so the count of free resources is decre- mented and the value false is left in the areg to indicate that the process can continue. if the count is zero then there are no free resources, and the process is added to the list of waiting processes, and the value true is left in areg to indicate that the process must wait. a conditional jump then tests areg and performs a stop if the process must wait. stop saves the iptr and wptr and deschedules the process, which will wait on the semaphore queue until another process performs a signal and subse- quently restarts the process with a run instruction. 7.9.2 freeing a resource when a process finishes with a resource and can free it, it performs a signal (or v), which is the following code sequence: ld semaphore; signal; cj continue; run; continue: the signal instruction is executed, with a pointer to the semaphore control block in areg . the action of signal depends on whether a process is waiting or not. if the front pointer of the process waiting list is empty then there are no processes waiting, so the count is incremented and areg is set to false . otherwise, at least one process is waiting, so the first process is remo ved from the list and placed in the breg , and areg is set to true . a conditional jump tests areg and performs a run to restart the process if there was one waiting. 7.10 sleep when the ST20-C1 becomes idle it disables counter distribution to its circuits and consumes a very small amount of electrical power; this is known as sleep mode. the counters are re-enabled and normal operation resumes automatically and instantly when either an interrupt or a software reset from the diagnostic controller is received. sleep mode may also be triggered directly from software by setting the sleep bit in the status register: ldc sleep; bitmask; statusset; in this case also, sleep mode persists until the next interrupt or software reset.
7.10 sleep 86/205 ?
87/205 8 instruction set reference ? 8 instruction set reference the following pages define the actions of each instruction in the ST20-C1 instruction set. the notation used is described in chapter 2. the use of the instructions is described in chapter 4, chapter 6 and chapter 7. the constants and data structures are listed in appendix a.
88/205 ? adc n add constant code: function 8 description: add a constant to areg . definition: if (sum > mostpos) { areg sum - 2 bitsperword if (status underflo w set ) status overflow set } else if (sum < mostneg) { areg sum + 2 bitsperword if (status overflow set ) status underflo w set } else { areg sum } where sum = areg + n the value of sum is calculated to unlimited precision status register: overflow or underflow bit may be set. comments: primary instruction. see also: add addc ldnlp section 4.4.
89/205 8 instruction set reference ? add add code: f4 description: add areg and breg . definition: if (sum > mostpos) { areg sum - 2 bitsperword if (status underflo w set ) status overflow set } else if (sum < mostneg) { areg sum + 2 bitsperword if (status overflow set ) status underflo w set } else { areg sum } breg creg creg areg where sum = areg + breg the value of sum is calculated to unlimited precision status register: overflow or underflow bit may be set. comments: secondary instruction. see also: adc addc section 4.4.
90/205 ? addc add with carry code: 21 f0 description: add areg and breg , unsigned, with carry propagation. this instruction is provided for long arithmetic; address calculations may be performed with add , sub and adc without affecting the carry flag. definition: if (sum < 2 bitsperword ) { areg unsigned sum status carry clear } else { areg unsigned sum - 2 bitsperword status carry set } breg creg creg areg where sum = areg unsigned + breg unsigned + status carry the value of sum is calculated to unlimited precision status register: carry bit is set or cleared. comments: secondar y instruction. see also: adc add subc section 4.4.
91/205 8 instruction set reference ? ajw n adjust work space code: function b description: move the workspace (stack) pointer by the number of words specified in the operand, in order to allocate or de-allocate workspace stack slots. definition: wptr wptr @ n status register: no effect comments: primary instruction. see also: fcall gajw section 4.10.
92/205 ? and and code: f9 description: bitwise and of areg and breg . definition: areg breg areg breg creg creg areg status register: no effect comments: secondar y instruction. see also: not or xor section 4.8.
93/205 8 instruction set reference ? arot anti-rotate stack code: f3 description: rotate the evaluation stack downwards. this instruction may be used to recover values rotated onto the bottom of the stack, e.g. by cj . definition: areg creg breg areg creg breg status register: no effect comments: secondary instruction. see also: dup rev rot section 4.1.
94/205 ? ashr arithmetic shift right code: 21 ff description: perform an arithmetic shift right of breg by areg bits, copying the sign bit into the vacated bits. breg , not areg , is rotated into creg , to preserve the value rather than the shift length. definition: areg ( breg >> arith areg unsigned ) breg creg creg breg status register: no effect comments: secondar y instruction. if areg is not in the range 0..31 then the result is undefined. see also: shl shr section 4.9.
95/205 8 instruction set reference ? biquad biquad iir filter step code: 21 f7 description: execute a step of a biquad iir filter on vectors of 16-bit values. areg points to the c coefficient vector, breg points to the x input data vector and creg points to the y results vector. areg must be word-aligned and breg and creg half- word aligned. biquad increments breg and creg by 2 bytes and performs the five multiply accumulates y[2] = x[0].c[0] + x[1].c[1] + x[2].c[2] + y[0].c[3] + y[1].c[4]. definition: if ( overflow ) if (status underflo w set ) status overflow set else if ( underflo w ) if (status overflow set ) status underflo w set else { sixteen [creg + 4] acc >> arith 23 breg breg + 2 creg creg + 2 } where acc = 1 << 22 + ((sixteen[areg] << shift) sixteen[breg]) + ((sixteen[areg+2] << shift) sixteen[breg+2]) + ((sixteen[areg+4] << shift) sixteen[breg+4]) + ((sixteen[areg+6] << shift) sixteen[creg]) + ((sixteen[areg+8] << shift) sixteen[creg+2]) the value of acc is calculated to 48-bit precision if (status mac_scale = 3) shift = 9 else shift = 4 status mac_scale status register: may set underflow or overflow. comments: areg must be word-aligned. breg and creg must be half-word aligned, and must either be both word-aligned or neither word-aligned. this instruction may take 8 memory accesses, which will affect interrupt latency. see also: mac, smacloop, umac chapter 5.
96/205 ? bitld load bit code: 22 f3 description: get a bit of breg . the bit number is given by areg . breg is rotated into creg , to preserve the value rather than the bit number. definition: areg ( breg >> areg) 1 breg creg creg breg status register: no effect comments: secondar y instruction. areg must be in the range 0..31. see also: bitst bitmask section 4.8.
97/205 8 instruction set reference ? bitmask create bit mask code: 22 f5 description: create a bit mask with a single bit set. the value in areg indicates the bit that is to be set. definition: areg 1 << areg status register: no effect comments: secondary instruction. areg must be in the range 0..31. see also: bitld section 4.8.
98/205 ? bitst store bit code: 22 f4 description: overwrite the bit position areg of the value in creg with a single bit with the value given by breg . breg is rotated into creg , to preserve the value rather than the bit number. definition: areg (creg ~(1 << areg)) (breg << areg) breg creg creg breg status register: no effect comments: secondar y instruction. areg must be in the range 0..31. breg must be 0 or 1. see also: bitld bitmask section 4.8.
99/205 8 instruction set reference ? breakpoint breakpoint code: ff description: take a breakpoint trap if a breakpoint trap is installed. definition: if ( breakpoint trap installed ) take breakpoint trap status register: if the trap is taken then the status register is saved and the trap handler status register is loaded. comments: secondary instruction. this instruction is a short secondar y instruction, encoded in a single byte. see also: chapter 6.
100/205 ? cj n conditional jump code: function a description: jump if areg is 0 (i.e. jump if false ). the destination of the jump is expressed as a byte offset from the instruction following the conditional jump. definition: if (areg = false) iptr next instruction + n else { areg breg breg creg creg areg } status register: no effect comments: primary instruction. the initial areg can be recovered using arot . see also: eqc gt gtu j jab section 4.6.
101/205 8 instruction set reference ? dequeue dequeue a process code: 23 f8 description: load into breg a pointer to the first process from the queue control block pointed to by areg . load into areg a boolean value indicating whether a process was found. the queue control block is defined in chapter 7. definition: if (frontptr = notprocess) -- queue is empty { areg false breg undefined } else -- queue is not empty { areg true breg frontptr if (frontptr = backptr) -- one process on queue word [areg @ q.fptrloc] notprocess else -- many processes on queue word [areg @ q.fptrloc] word[ frontptr @ pw.link ] } creg undefined where frontptr = word[areg @ q.fptrloc] backptr = word[areg @ q.bptrloc] status register: no effect comments: secondary instruction. this instruction may require 4 memory accesses. if the queue structure is in off- chip memory then interrupt latency may be affected. areg must be word aligned (i.e. divisible by 4). see also: enqueue run chapter 7.
102/205 ? divstep divide step code: 21 f8 description: perform a step of an integer division to generate 4 bits of the quotient. areg holds the positive divisor. breg and creg hold the non-negative dividend or partial remainder and the partial result. before the first step, breg holds the dividend and creg must be 0. after performing divstep 8 times, breg will hold the quotient and creg the remainder. definition: if (areg > 0 and breg 0 and creg 0) { breg (breg << 4) (part_div / areg) creg part_div rem areg } else { breg undefined creg undefined } where part_div = (creg << 4) (breg >> 28) the value of part_div is calculated to unlimited precision status register: no effect. comments: secondar y instruction. areg must be greater than zero. breg and creg must be not less than zero. see also: unsign section 4.4.
103/205 8 instruction set reference ? dup duplicate top of stack code: f1 description: duplicate the top of the integer stack. definition: breg areg creg breg status register: no effect comments: secondary instruction. see also: arot rev rot section 4.8.
104/205 ? ecall exception call code: 23 f1 description: take a trap with exception level indicated by areg . this instruction can be used to implement system calls to an operating system. definition: areg breg breg creg creg areg if (trap level areg is installed) take trap level areg status register: the status register is saved and a new status register with set values is loaded. comments: secondar y instruction. areg must be in the range lowestexception to highestexception . the exception type must be exceptionprocesstype . see also: eret chapter 6.
105/205 8 instruction set reference ? enqueue enqueue a process code: 23 f7 description: add the process indicated by the process descriptor in breg to the queue structure in areg . the queue control block is defined in chapter 7. definition: if (word[areg @ q.fptrloc] = notprocess) -- queue is empty { word [areg @ q.fptrloc] breg word [ areg @ q.bptrloc] breg } else { word [word[areg @ q.bptrloc] @ pw.link] breg word [ areg @ q.bptrloc] breg } areg undefined breg undefined creg undefined status register: no effect comments: secondary instruction. this instruction may require 4 memory accesses. if the queue structure is in off- chip memory then interrupt latency may be affected. areg must be word aligned (i.e. divisible by 4). see also: dequeue, stop chapter 7.
106/205 ? eqc n equals constant code: function c description: compare areg to a constant. definition: if (areg = n) areg true else areg false status register: no effect comments: primary instruction. see also: cj gt gtu section 4.6.
107/205 8 instruction set reference ? eret exception return code: 23 f2 description: return from an interrupt or trap. definition: if (status trap_mode = clear) signal interrupt return to interrupt controller areg word[wptr @ ex.interptdareg] breg word[wptr @ ex.interptdbreg] creg word[wptr @ ex.interptdcreg] wptr word[wptr @ ex.interptdwptr] iptr word[wptr @ ex.interptdiptr] tdesc word[wptr @ ex.interptdtdesc] status word[wptr @ ex.interptdstatus] status register: saved status register is restored. comments: secondary instruction. the interrupted wptr must be word aligned. see also: ecall chapter 6 .
108/205 ? fcall n function call code: function 9 description: call subroutine at the specified byte offset. definition: word [wptr @ 0] iptr iptr next instruction + n status register: no effect comments: primary instruction. see also: ajw jab section 4.4.
109/205 8 instruction set reference ? gajw general adjust workspace code: 23 fb description: set the workspace pointer to the word aligned address in areg , saving the previous value in areg . definition: wptr areg areg wptr status register: no effect comments: secondary instruction. areg should be word aligned (i.e. divisible by 4). see also: ajw fcall section 4.4.
110/205 ? gt greater than code: 21 fb description: compare the top two elements of the stack, returning true if breg is greater than areg . definition: if (breg > areg) areg true else areg false breg creg creg areg status register: no effect comments: secondar y instruction. see also: eqc gtu order section 4.6.
111/205 8 instruction set reference ? gtu greater than unsigned code: 21 fc description: compare the top two elements of the stack, treating both as unsigned integers, returning true if breg is greater than areg . definition: if (breg unsigned > areg unsigned ) areg true else areg false breg creg creg areg status register: no effect comments: secondary instruction. see also: eqc gt orderu section 4.6.
112/205 ? io input/output code: 23 fd description: set, clear and test bits of the io register. the bits set in the least significant half word of breg are cleared in the io register and then the bits set in the least significant half word of areg are set in the io register. the initial io register is copied into the areg . definition: ioreg (ioreg (~breg #ffff0000)) (areg #ffff) areg ioreg breg creg creg areg status register: no effect comments: secondar y instruction. some bits of the io register may be reserved in some variants. see the datasheet for the variant. see also: bitmask section 4.11.
113/205 8 instruction set reference ? j n jump code: function 0 description: unconditional relative jump. the destination of the jump is expressed as a byte offset from the first b yte after the current instruction. definition: iptr next instruction + n status register: no effect. comments: primary instruction. see also: cj jab section 4.6.
114/205 ? jab jump absolute code: fd description: jump to the address in areg , saving the previous address in creg . this instruction can be used for function and procedure returns and to jump to a run-time computed location. definition: iptr areg areg breg breg creg creg iptr status register: no effect comments: secondar y instruction. see also: cj j section 4.4.
115/205 8 instruction set reference ? lbinc load byte and increment code: 22 fa description: load the unsigned byte addressed by areg into areg and increment the address by one byte. definition: areg 0..7 byte[areg] areg 8..bitsperword-1 0 creg areg + 1 status register: no effect comments: secondary instruction. see also: ldl ldnl lsinc lwinc sbinc section 4.2.
116/205 ? ldc n load constant code: function 4 description: load constant into areg . definition: areg n breg areg creg breg status register: no effect comments: primary instruction. see also: adc ldl section 4.2.
117/205 8 instruction set reference ? ldl n load local code: function 7 description: load into areg the local variable at the specified word offset in workspace. ldl cannot read from addresses reserved for peripheral registers. definition: areg word[wptr @ n] breg areg creg breg status register: no effect comments: primary instruction. areg must be word aligned (i.e. divisible by 4). see also: ldnl stl section 4.2.
118/205 ? ldlp n load local pointer code: function 1 description: load into areg the address of the local variable at the specified offset in workspace. definition: areg wptr @ n breg areg creg breg status register: no effect comments: primary instruction. see also: ldl ldnlp section 4.5.
119/205 8 instruction set reference ? ldnl n load non-local code: function 3 description: load into areg the non-local variable at the specified word offset from areg . definition: areg word[areg @ n] status register: no effect comments: primary instruction. areg must be word aligned (i.e. divisible by 4). see also: ldl ldnlp stnl section 4.2.
120/205 ? ldnlp n load non-local pointer code: function 5 description: load into areg the address at the specified word offset from the address in areg . definition: areg areg @ n status register: no effect comments: primary instruction. see also: ldlp ldnl wsub section 4.5.
121/205 8 instruction set reference ? ldpi load pointer to instruction code: 23 fa description: load into areg an absolute address calculated from an offset relative to the current instruction pointer. areg contains a byte offset which is added to the address of the first b yte following this instruction. definition: areg next instruction + areg status register: no effect comments: secondary instruction. see also: jab section 4.5.
122/205 ? ldprodid load product identity code: 23 fc description: load a value indicating the product identity into areg. each product in the st20 family has a unique product identity code. definition: areg productid breg areg creg breg status register: no effect comments: secondar y instruction. different st20 products may use the same processor type, but return different product identity codes. however a product identity code uniquely defines the processor type used in that product. for specific product identities in the st20 family refer to sgs-thomson. see also: section 4.2.
123/205 8 instruction set reference ? ldtdesc load task descriptor code: 23 f9 description: load the task descriptor of the current task. definition: areg tdesc breg areg creg breg status register: no effect comments: secondary instruction. see also: ldlp ldpi chapter 6 .
124/205 ? lsinc load sixteen and increment code: 22 fc description: load the unsigned 16-bit object addressed by areg into areg and increment the address by two bytes. definition: areg 0..15 sixteen[areg] areg 16..bitsperword-1 0 creg areg + 2 status register: no effect comments: secondar y instruction. areg must be half-word aligned (i.e. divisible by 2). see also: lbinc ldl lsxinc lwinc ssinc section 4.2.
125/205 8 instruction set reference ? lsxinc load sixteen sign extended and increment code: 22 fd description: load the signed 16-bit object addressed by areg into areg , sign extend to a word, and increment the address by two bytes. definition: areg 0..15 sixteen[areg] areg 16..bitsperword-1 sixteen[areg] 15 creg areg + 2 status register: no effect comments: secondary instruction. areg must be half-word aligned (i.e. divisible by 2). see also: ldl lsinc lwinc ssinc xsword section 4.2.
126/205 ? lwinc load word and increment code: 22 ff description: load a variable from the address given in areg and increment the address by one word. this instruction may be used with stinc as a step in a block move, and breg is not modified so that it can be used to hold the store address . definition: areg word[areg] creg areg @ 1 status register: no effect comments: secondar y instruction. areg must be word aligned (i.e. divisible by 4). see also: lbinc lsinc swinc section 4.2.
127/205 8 instruction set reference ? mac multiply accumulate code: 21 f2 description: multiply areg and breg , and add in creg . the most significant word of the result is placed in breg and the least significant in areg . this can be used in forming the double length product of areg and breg , with creg as carry in, treating the areg and breg values as signed but creg as unsigned. definition: areg low_word ( accum64) breg high_word ( accum64) creg areg where accum64 = (breg areg) + creg unsigned the value of accum64 is calculated as a 64-bit value status register: no effect comments: secondary instruction. see also: ldiv mul umac chapter 5 .
128/205 ? mul multiply code: f6 description: multiply areg by breg , with checking for overflow but no carry. definition: areg low_word ( prod) if (prod > mostpos) { if (status underflo w set ) status overflow set } else if (prod < mostneg) { if (status overflow set ) status underflo w set } breg creg creg areg where prod = areg breg the value of prod is calculated to unlimited precision status register: overflow or underflow bit may be set. comments: secondar y instruction. see also: add mac section 4.4.
129/205 8 instruction set reference ? nop no operation code: 23 ff description: perform no operation. definition: no change status register: no effect comments: secondary instruction.
130/205 ? not bitwise not code: f8 description: complement bits in areg . definition: areg ~ areg status register: no effect comments: secondar y instruction. see also: and or xor section 4.8.
131/205 8 instruction set reference ? or or code: fa description: bitwise or of areg and breg . definition: areg breg areg breg creg creg areg status register: no effect comments: secondary instruction. see also: and not xor section 4.8.
132/205 ? order order code: 21 fd description: order areg and breg into signed ascending order, so that breg is greater than or equal to areg . this can be used to implement maximum, minimum, absolute value and saturation at less than 32 bits. definition: if (areg > breg) { areg breg breg areg } status register: no effect comments: secondar y instruction. see also: gt orderu rev section 4.6.
133/205 8 instruction set reference ? orderu unsigned order code: 21 fe description: order areg and breg into unsigned ascending order, so that breg is greater than or equal to areg . this can be used to implement unsigned maximum and minimum. definition: if (areg unsigned > breg unsigned ) { areg breg breg areg } status register: no effect comments: secondary instruction. see also: gtu order rev section 4.6.
134/205 ? rev reverse code: f0 description: swap the values in areg and breg . definition: areg breg breg areg status register: no effect comments: secondar y instruction. see also: dup order orderu rot section 4.8.
135/205 8 instruction set reference ? rmw memory read modify write code: 22 f9 description: clear and set bits of the memory word at address areg using the set mask in breg and clear mask in creg . definition: word [areg] (word[areg] ~creg) breg areg word[areg] breg areg creg breg status register: no effect comments: secondary instruction. areg must be word aligned (i.e. divisible by 4). see also: bitmask section 4.8.
136/205 ? rot rotate stack code: f2 definition: rotate the evaluation stack upwards. definition: areg breg breg creg creg areg status register: no effect comments: secondar y instruction. see also: arot dup rev section 4.8.
137/205 8 instruction set reference ? run run process code: 23 f3 description: spawn a new process. add the new process to the back of the process queue defined b y the control block at schedulerqptr . the task descriptor of the process is in areg ; this identifies the process descr iptor block. the instruction pointer and work space pointer must have been written in the process descriptor block of the process at offsets pw.iptr and pw.wptr words. definition: if ( run trap handler installed ) take run trap else { if (word [schedulerqptr @ q.fptrloc] = notprocess) -- queue is empty { word [schedulerqptr @ q.fptrloc] areg word [ schedulerqptr @ q.bptrloc] areg } else { word [ word [schedulerqptr @ q.bptrloc] @ pw.link] areg word [ schedulerqptr @ q.bptrloc] areg } areg undefined breg undefined creg undefined } status register: no effect comments: secondary instruction. areg must be word aligned (i.e. divisible by 4). this instruction may require up to three on-chip memory accesses and one off- chip. this may affect interrupt latency. see also: dequeue enqueue signal stop chapter 7 .
138/205 ? saturate saturate arithmetic result code: 21 fa description: saturate the value in areg to mostpos or mostneg if overflow or underflow respectively has occurred, and clear the overflow or underflow. definition: if (status overflow ) areg mostpos else if (status underflo w ) areg mostneg status overflow clear status underflo w clear status register: overflow and underflow bits are cleared. comments: secondar y instruction. see also: adc add mul smul sub section 4.4.
139/205 8 instruction set reference ? sbinc store byte and increment code: 22 fb description: store the least significant b yte of breg into the byte of memory addressed by areg and increment the address by one byte. definition: byte [areg] breg 0..7 areg creg breg areg + 1 creg breg status register: no effect comments: secondary instruction. see also: lbinc ssinc swinc stnl section 4.2.
140/205 ? shl shift left code: fb description: logical shift of breg left by areg bits, filling with z ero bits. if the initial areg is not between 0 and 31 inclusive then the result is undefined. definition: areg breg << areg breg creg creg breg status register: no effect comments: secondar y instruction. areg must be in the range 0..31. see also: shr section 4.9.
141/205 8 instruction set reference ? shr shift right code: fc description: logical shift of breg right by areg places, filling with z ero bits. if the initial areg is not between 0 and 31 inclusive then the result is undefined. definition: areg breg >> areg breg creg creg breg status register: no effect comments: secondary instruction. areg must be in the range 0..31. see also: ashr shl section 4.9.
142/205 ? signal signal code: 23 f5 description: perform the first par t of a semaphore signal (or v) on the semaphore pointed to by areg . if no process is waiting then the unsigned count is incremented. if processes are waiting then the first process is removed from the queue and its identifier placed in breg ready to be run. the instruction returns a boolean value in areg stating whether a run process is required. this instruction should be used in the following sequence: ld semptr; signal; cj continue; run; continue : definition: if (frontptr = notprocess) -- queue empty { word [areg @ s.count] word[areg @ s.count] + 1 areg false breg undefined } else -- queue not empty { if (frontptr = backptr) -- one process on queue word [areg @ s.front] notprocess else -- many processes on queue word [areg @ s.front] word[ frontptr @ pw.link ] areg true breg frontptr } creg undefined where frontptr = word[areg @ s.front] backptr = word[areg @ s.back] status register: no effect comments: secondar y instruction. the increment of the count is unchecked. this instruction may require 4 accesses to memory. the semaphore structure should be placed in on-chip memory if interrupt latency is critical. see also: run wait chapter 7 .
143/205 8 instruction set reference ? smacinit initialize short multiply accumulate loop code: 21 f5 description: set the loop count, buffer size, scaling and data format for the smacloop instruction. definition: status mac_count areg #ff status mac_buffer (areg >> 8) #7 status mac_scale ( areg >> 11) #3 status mac_mode (areg >> 13) #1 areg breg breg creg creg 0 status register: no effect. comments: secondary instruction. see also: smacloop chapter 5 .
144/205 ? smacloop short multiply accumulate loop code: 21 f6 description: multiply pairs of signed16-bit values and accumulate the products. on entry areg and breg contain the addresses of arrays x and y of 16-bit values and creg holds the initial 32-bit accumulator. on exit the accumulator is in areg , while breg and creg contain the next addresses in the x and y arrays respectively. the x values can be in a circular buffer whose address is exactly divisible by the size. the loop count, buffer size, mode and scaling codes, held in the status register, may be set by the smacinit instruction. warning: this instruction is not interruptible. if interrupt latency is critical then a similar result may be achieved by executing the instruction many times with small counts. the result may not be the same, since rounding occurs at the end of the instruction from the internal 48-bit accumulator to a 32-bit result. definition: if (status overflow ) areg max else if (status underflo w ) areg min else if ( overflow ) { status overflow set areg max } else if ( underflow ) { status underflo w set areg min } else { areg acc >> arith shift1 } breg xaddress (status mac_count ) creg breg + (2 status mac_count ) where acc = (creg << shift1) + (1 << (shift1-1)) + s i=0..n-1 [sixteen[xaddress(i )] (sixteen[breg + 2.i] << shift2)] the value of acc is calculated to 48-bit precision if (status mac_count = 0) n=256
145/205 8 instruction set reference ? else n = status mac_count if (status mac_buffer 0) { buff_size = 4 << status mac_buffer xaddress (i) = areg - (areg rem buff_size) + ((areg + 2.i ) rem buff_size) } else xaddress(i) = areg + (2 i) if (status mac_mode = longmode ) { shift1 = 7 max = mostpos min = mostneg } else { shift1 = 23 max = #7fff min = #8000 } if (status mac_scale = 3) shift2 = 9 else shift2 = 4 status mac_scale status register: overflow or underflow may be set. comments: secondary instruction. areg must be half-word aligned. breg must be word aligned. see also: biquad mac mul smacinit chapter 5 .
146/205 ? smul short multiply code: 21 f4 description: multiply areg by breg , treated as sixteen bit signed integers. definition: areg (int16)areg (int16)breg breg creg creg areg status register: no effect comments: secondar y instruction. areg and breg must be in the range of 16-bit signed integers. see also: mul smac section 4.4.
147/205 8 instruction set reference ? ssinc store sixteen and increment code: 22 fe description: store the least significant 16 bits of breg into the half word of memory addressed by areg and increment the address by two bytes. definition: sixteen [areg] breg 0..15 areg creg breg areg + 2 creg breg status register: no effect comments: secondary instruction. areg must be half-word aligned (i.e. divisible by 2). see also: lsinc lsxinc sbinc stl stnl swinc section 4.2.
148/205 ? statusclr clear bits in status register code: 22 f7 description: clear the bits of the status register which are set in the areg . the initial status register value is returned in the areg . definition: areg status status status ~areg status register: the bits of areg which are set will be cleared in the status register. comments: secondar y instruction. see also: statusset statustst section 4.12.
149/205 8 instruction set reference ? statusset set bits in status register code: 22 f6 description: set the bits of the status register which are set in areg . the initial status register value is returned in the areg . definition: areg status status status areg status register: the bits of areg which are set will be set in the status register. comments: secondary instruction. see also: statusclr statustst section 4.12.
150/205 ? statustst test status register code: 22 f8 description: test the bits of the status register which are set in the areg . definition: areg status areg status register: no effect comments: secondar y instruction. see also: bitmask statusclr statusset section 4.12.
151/205 8 instruction set reference ? stl n store local code: function d description: store the contents of areg into the local variable at the specified w ord offset in workspace. this instruction cannot write to addresses reserved for peripheral registers. definition: word [wptr @ n] areg areg breg breg creg creg areg status register: no effect comments: primary instruction. see also: ldl sbinc ssinc stnl section 4.2.
152/205 ? stnl n store non-local code: function e description: store the contents of breg into the non-local variable at the specified word offset from areg. definition: word [areg @ n] breg areg creg breg areg creg breg status register: no effect comments: primary instruction. areg must be word aligned (i.e. divisible by 4). see also: ldnl sbinc ssinc swinc stl section 4.2.
153/205 8 instruction set reference ? stop stop process code: 23 f4 description: terminate the current process, saving the current iptr and wptr for later use, and start the next process from the scheduling queue. if the scheduling queue is empty then the cpu will become idle. this instruction is implemented in two stages to protect interrupt latency. the first stage deschedules the current process and sets the start_next_task status bit. the second stage clears the start_next_task status bit and starts the next process. an interrupt may occur between the two stages. definition: if ( stop trap handler installed ) take stop trap else { word [tdesc @ pw.iptr] next instruction word [tdesc @ pw.wptr] wptr status local_interrupt_enable set status overflow clear status undeflo w clear status carry clear status interrupt_mode clear status trap_mode clear status start_next_task clear status timeslice_count maxtimeslicecount -- start next process on scheduling queue if (frontptr = notprocess) -- queue is empty, so become idle { status sleep set status user_mode clear if ( idle trap handler installed ) take idle trap else set idle } else -- processes waiting, so start next process { status sleep clear status user_mode set tdesc frontptr wptr word [frontptr @ pw.wptr]
154/205 ? iptr word [frontptr @ pw.iptr] if (frontptr = backptr) --one process on queue, so make it empty word [schedulerqptr @ q.fptrloc] notprocess else -- many processes, so remove first word [schedulerqptr @ q.fptrloc] word[frontptr @ pw.link] } areg undefined breg undefined creg undefined } where frontptr = word[schedulerqptr @ q.fptrloc] backptr = word[schedulerqptr @ q.bptrloc] status register: global interrupt enable and timeslice enable are preserved. start_next_task is set when the current process is descheduled and cleared when the new process is started. an interrupt may occur between these two stages. other bits are set to the values listed above. comments: secondar y instruction. deschedules the current process. this instruction must not be used in an exception handler. see also: dequeue enqueue run wait chapter 7 .
155/205 8 instruction set reference ? sub subtract code: f5 description: subtract areg from breg , with checking for overflow. definition: if (diff > mostpos) { areg diff - 2 bitsperword if (status underflo w set ) status overflow set } else if (diff < mostneg) { areg diff + 2 bitsperword if (status overflow set ) status underflo w set } else { areg diff } breg creg creg areg where diff = breg - areg the value of diff is calculated to unlimited precision status register: overflow or underflow bit may be set. comments: secondary instruction. see also: add subc section 4.4.
156/205 ? subc subtract with carry code: 21 f1 description: subtract areg from breg , unsigned with carry propagation. this instruction is provided for long arithmetic; address calculations may be performed with add , sub and adc without affecting the carry flag. definition: if ( diff 0) { areg unsigned diff status carry clear } else { areg unsigned diff + 2 bitsperword status carry set } breg creg creg areg where diff = ( breg unsigned - areg unsigned ) - status carry the value of diff is calculated to unlimited precision status register: carry bit is set or cleared. comments: secondar y instruction. see also: addc sub section 4.4.
157/205 8 instruction set reference ? swap32 byte swap 32 code: 23 fe description: reverse the order of the bytes within areg . definition: areg (areg 0..7 << 24) (areg 8..15 << 16) (areg 16..23 << 8) areg 24..31 status register: no effect comments: secondary instruction. see also: section 4.9.
158/205 ? swinc store word and increment code: 23 f0 description: store the value from the breg at the memory address given in the initial areg and increment the address by one word. this instruction may be used with lwinc as a step in a block move. the value in creg is copied into the areg . definition: word [areg] breg areg creg breg areg @ 1 creg breg status register: no effect comments: areg must be word aligned (i.e. divisible by 4). secondar y instruction. see also: ldinc sbinc ssinc stnl section 4.2.
159/205 8 instruction set reference ? timeslice timeslice code: fe description: deschedules the current process and starts the next task if a timeslice is due and timeslicing is enabled. this instruction is implemented in two stages to protect interrupt latency. the first stage deschedules the current process (even if the queue is empty), adds it to the back of the scheduling queue and sets the start_next_task status bit. the second stage clears the start_next_task status bit and starts the next process from the scheduling queue. an interrupt may occur between the two stages. definition: if ( status timeslicing enabled and status timeslice_count =0 ) { if ( timeslice trap installed ) take timeslice trap else { -- save state of current process word [tdesc @ pw.iptr] next instruction word [tdesc @ pw.wptr] wptr if (frontptr notprocess) -- queue not empty { -- add current process to scheduling queue word [backptr @ pw.link] tdesc word [schedulerqptr @ q.bptrloc] tdesc -- remove front process from queue word [schedulerqptr @ q.fptrloc] word[frontptr @ pw.link] -- start next process from scheduling queue tdesc frontptr wptr word [frontptr @ pw.wptr] iptr word [frontptr @ pw.iptr] } status local_interrupt_enable set status overflow clear status undeflo w clear status carry clear status user_mode set status interrupt_mode clear status trap_mode clear status sleep clear status start_next_task clear
160/205 ? status timeslice_count maxtimeslicecount areg undefined breg undefined creg undefined } } where frontptr = word[schedulerqptr @ q.fptrloc] backptr = word[schedulerqptr @ q.bptrloc] status register: global interrupt enable and timeslice enable preserved. start_next_task is set when the current process is descheduled and cleared when the new process is started. an interrupt may occur between these two stages. other bits are set to the values listed above. comments: secondar y instruction. this instruction must not be used in an exception handler. see also: stop run chapter 7.
161/205 8 instruction set reference ? umac unsigned multiply accumulate code: 21 f3 description: multiply areg by breg, adding in creg, to form a double word result, treating the initial values as unsigned. this can be used in forming the double length product of areg and breg , with creg as carry in. definition: areg unsigned low_word (prod) breg unsigned high_word (prod) creg areg where prod = (breg unsigned areg unsigned ) + creg unsigned the value of prod is calculated to unlimited precision status register: no effect comments: secondary instruction. see also: mac chapter 5 .
162/205 ? unsign unsign argument code: 21 f9 description: remove the sign of the value in areg and exclusive-or it with a sign flag in breg . definition: if (areg 0) { areg breg breg areg } else { areg 1 - breg breg - areg } status register: no effect comments: secondar y instruction to aid the implementation of signed division. breg must be 0 or 1. see also: divstep section 4.4.
163/205 8 instruction set reference ? wait wait code: 23 f6 description: perform the first par t of a semaphore wait (or p) on the semaphore pointed to by areg . if the semaphore count is non-zero then the count is decremented and the process continues; otherwise the current process is added to the back of the semaphore list ready for the current process to be descheduled. the instruction returns a boolean value in areg stating whether a process deschedule is required. the instruction should be used in the following sequence: ld semptr; wait; cj continue; stop; continue: definition: if (word[areg @ s.count] 0) { word [areg @ s.count] word[areg @ s.count] - 1 areg false } else { if (frontptr = notprocess) -- queue empty so add to queue { word [areg @ s.front ] tdesc word [areg @ s.back ] tdesc } else -- queue not empty so add to back of queue { word [backptr @ pw.link] tdesc word [areg @ s.back ] tdesc } areg true } breg undefined creg undefined where frontptr = word[areg @ s.front] backptr = word[areg @ s.back] status register: no effect comments: secondary instruction. areg must be word-aligned. the semaphore structure should be in fast memory if interrupt latency is critical. see also: signal stop chapter 7 .
164/205 ? wsub word subscript code: f7 description: generate the address of the element which is indexed by breg in the word array pointed to by areg . definition: areg areg @ breg breg creg creg areg status register: no effect comments: secondar y instruction. see also: ldlp ldnlp section 4.5.
165/205 8 instruction set reference ? xbword sign extend byte to word code: 22 f1 description: sign-extend the value in the least significant byte of areg into a signed word. definition: areg 0..7 areg 0..7 areg 8..bitsperword-1 areg 7 status register: no effect comments: secondary instruction. see also: xsword section 4.4.6.
166/205 ? xor exclusive or code: 21 f0 description: bitwise exclusive or of areg and breg . definition: areg breg ? areg breg creg creg areg status register: no effect comments: secondar y instruction. see also: and not or section 4.8.
167/205 8 instruction set reference ? xsword sign extend sixteen to word code: 22 f2 description: sign extend the value in the least significant 16 bits of areg to a signed word. definition: areg 0..15 areg 0..15 areg 16..bitsperword-1 areg 15 status register: no effect comments: secondary instruction. see also: xbword section 4.4.6.
168/205 ? appendices
169/205 ? a constants and data structures this appendix gives a full listing of all the constants and data structures used in this document, with brief descriptions and values.
170/205 ? a.1 status register a.2 exception levels full name bit numbers meaning when set or meaning of value mac_count 0 - 7 multiply-accumulate number of steps. mac_buffer 8 - 10 multiply-accumulate data buffer size code. mac_scale 11 - 12 multiply-accumulate scaling code. mac_mode 13 multiply-accumulate accumulator format code. global_interrupt_disable 14 disable external interrupts until explicitly enabled. local_interrupt_disable 15 disable external interrupts until process descheduled. overflo w 16 an arithmetic operation gave a positive overflow. underflo w 17 an arithmetic operation gave a negative overflow. carry 18 an arithmetic operation produced a carry. user_mode 19 a user process is executing. interrupt_mode 20 an interrupt handler is executing. trap_mode 21 a trap handler is executing. sleep 22 the processor is due to go to sleep. reserved 23 reserved. start_next_task 24 the cpu must start executing a new process. timeslice_enable 25 timeslicing is enabled. timeslice_count 26 - 31 timeslice clock. table a.1 status register bits (see section 3.3.2) exception level name description 0 - 255 user exception user exception levels. -1 el_breakpoint_trap breakpoint trap. -2 el_illegal_instr_trap illegal op-code trap. -3 el_idle_trap cpu idle trap. -4 el_schedule_exception_trap schedule user process as exception trap. -5 el_run_trap run process trap. -6 el_stop_trap stop process trap. -7 el_timeslice_trap timeslice trap. table a.2 exception levels (see chapter 6)
171/205 ? a.3 data structures this section defines the data structures used by the ST20-C1 core. name word offset purpose ex.handleriptr 7 exception handler instruction pointer. ex.interptdstatus 6 interrupted process status register. ex.interptdtdesc 5 interrupted process task descriptor. ex.interptdiptr 4 interrupted process instruction pointer. ex.interptdwptr 3 interrupted process stack pointer. ex.interptdcreg 2 interrupted process creg. ex.interptdbreg 1 interrupted process breg. ex.interptdareg 0 interrupted process areg. table a.3 exception handler (see chapter 6) name word offset purpose pw.iptr 2 the instruction pointer. pw.wptr 1 the instruction pointer. pw.link 0 the link to the next process in the list. table a.4 process descriptor block (see section 3.3.4) name word offset purpose q.bptrloc 1 the last process in the waiting process list. q.fptrloc 0 the first process in the w aiting process list. table a.5 waiting process list data structure (see section 7.1) name word offset purpose s.back 2 the last process in the semaphore waiting list. s.front 1 the first process in the semaphore w aiting list. s.count 0 the unsigned number of extraprocesses that the semaphore will allow to continue running on a wait request. table a.6 semaphore data structure (see section 7.9)
172/205 ? a.4 miscellaneous constants this section lists the constants which are used in this manual. name value meaning bitsperword 32 the number of bits in a word. bytesperword 4 the number of bytes in a word. exceptionbase #80000040 the base of the exception descriptor area. exceptionproc- esstype #1 bit 0 of exception vector table entry for an exception. false 0 the boolean value `false'. highestexception 255 highest permitted exception level. longmode 1 smacloop q15 data format. lowestexception -7 lowest permitted exception level. maxtimeslicecount 63 maximum value of timeslice count. mostneg #80000000 the most negative integer value. mostpos #7fffffff the most positive signed integer value. notprocess mostneg #80000000 used, wherever a process descriptor is expected, to indi- cate that there is no process. productid depends on processor type. a value used to identify the type and revision of processor, returned by the ldprodid instruction. savedtaskdescriptor #800000008 address where user process exception is saved when a schedule exception trap occurs. schedulerqptr mostneg #80000000 the address of the process list data structure for the scheduler list. shortmode 0 smacloop q31 data format. true 1 the boolean value `true'. userprocesstype #0 bit 0 of exception vector table entry for a user process. table a.7 constants
173/205 ?
174/205 ? b instruction set summary this appendix gives a full listing of all the instructions and instruction components, both in function code and alphabetical order. the `memory' column gives, in hexadec- imal, the bytes that appear in memory. for primary instructions, this includes a data value, which is represented by n . b.1 function code order b.1.1 primary instructions code memory mnemonic name 00 njn jump 11 n ldlp n load local pointer 22 npfixn prefix 33 n ldnl n load non-local 44 n ldc n load constant 55 n ldnlp n load non-local pointer 66 nnfixn negative prefix 77 n ldl n load local 88 n adc n add constant 99 n fcall n function call aa ncjn conditional jump bb n ajw n adjust work space cc n eqc n equals constant dd n stl n store local ee n stnl n store non-local ff n opr n operate b.1.2 secondary instructions code memory mnemonic name 00 f0 rev reverse 01 f1 dup duplicate 02 f2 rot rotate stack 03 f3 arot anti-rotate stack 04 f4 add add 05 f5 sub subtract 06 f6 mul multiply 07 f7 wsub word subscript 08 f8 not bitwise not 09 f9 and and 0a fa or or 0b fb shl shift left 0c fc shr shift right 0d fd jab jump absolute 0e fe timeslice timeslice 0f ff breakpoint breakpoint
175/205 ? 10 21 f0 addc add with carry 11 21 f1 subc subtract with carry 12 21 f2 mac multiply accumulate 13 21 f3 umac unsigned multiply accumulate 14 21 f4 smul short multiply 15 21 f5 smacinit initialize short multiply accumulate loop 16 21 f6 smacloop short multiply accumulate loop 17 21 f7 biquad biquad iir filter step 18 21 f8 divstep divide step 19 21 f9 unsign unsign argument 1a 21 fa saturate saturate 1b 21 fb gt greater than 1c 21 fc gtu greater than unsigned 1d 21 fd order order 1e 21 fe orderu unsigned order 1f 21 ff ashr arithmetic shift right 20 22 f0 xor exclusive or 21 22 f1 xbword sign extend byte to word 22 22 f2 xsword sign extend sixteen to word 23 22 f3 bitld load bit 24 22 f4 bitst store bit 25 22 f5 bitmask create bit mask 26 22 f6 statusset set bits in status register 27 22 f7 statusclr clear bits in status register 28 22 f8 statustst test status register 29 22 f9 rmw read modify write 2a 22 fa lbinc load byte and increment 2b 22 fb sbinc store byte and increment 2c 22 fc lsinc load sixteen and increment 2d 22 fd lsxinc load sixteen sign extended and increment 2e 22 fe ssinc store sixteen and increment 2f 22 ff lwinc load word and increment 30 23 f0 swinc store word and increment 31 23 f1 ecall exception call 32 23 f2 eret exception return 33 23 f3 run run process 34 23 f4 stop stop process 35 23 f5 signal signal 36 23 f6 wait wait 37 23 f7 enqueue enqueue a process 38 23 f8 dequeue dequeue a process 39 23 f9 ldtdesc load task descriptor 3a 23 fa ldpi load pointer to instruction 3b 23 fb gajw general adjust workspace 3c 23 fc ldprodid load product identity 3d 23 fd io input/output 3e 23 fe swap32 byte swap 32 3f 23 ff nop no operation
176/205 ? b.2 alphabetical order mnemonic code memory name adc n primary 8 8 n add constant add secondar y 04 f4 add addc secondar y 10 21 f0 add with carry ajw n primary b b n adjust work space and secondar y 09 f9 and arot secondar y 03 f3 anti-rotate stack ashr secondar y 1f 21 ff arithmetic shift right biquad secondar y 17 21 f7 biquad iir filter step bitld secondar y 23 22 f3 load bit bitmask secondar y 25 22 f5 create bit mask bitst secondar y 24 22 f4 store bit breakpoint secondar y 0f ff breakpoint cj n primary a a n conditional jump dequeue secondar y 38 23 f8 dequeue a process divstep secondar y 18 21 f8 divide step dup secondar y 01 f1 duplicate ecall secondar y 31 23 f1 exception call enqueue secondar y 37 23 f7 enqueue a process eqc n primary c c n equals constant eret secondar y 32 23 f2 exception return fcall n primary 9 9 n function call gajw secondar y 3b 23 fb general adjust workspace gt secondar y 1b 21 fb greater than gtu secondar y 1c 21 fc greater than unsigned io secondar y 3d 23 fd input/output jn primary 0 0 n jump jab secondar y 0d fd jump absolute lbinc secondar y 2a 22 fa load byte and increment ldc n primary 4 4 n load constant ldl n primary 7 7 n load local ldlp n primary 1 1 n load local pointer ldnl n primary 3 3 n load non-local ldnlp n primary 5 5 n load non-local pointer ldpi secondar y 3a 23 fa load pointer to instruction ldprodid secondar y 3c 23 fc load product identity ldtdesc secondar y 39 23 f9 load task descriptor lsinc secondar y 2c 22 fc load sixteen and increment lsxinc secondar y 2d 22 fd load sixteen sign extended and increment lwinc secondar y 2f 22 ff load word and increment mac secondar y 12 21 f2 multiply accumulate mul secondar y 06 f6 multiply nfix n primary 4 4 n negative prefix nop secondar y 3f 23 ff no operation not secondar y 08 f8 bitwise not opr n primary f f n operate or secondar y 0a fa or order secondar y 1d 21 fd order orderu secondar y 1e 21 fe unsigned order
177/205 ? pfix n primary 2 2 n prefix rev secondary 00 f0 reverse rmw secondary 29 22 f9 read modify write rot secondary 02 f2 rotate stack run secondary 33 23 f3 run process saturate secondary 1a 21 fa saturate sbinc secondary 2b 22 fb store byte and increment shl secondary 0b fb shift left shr secondary 0c fc shift right signal secondary 35 23 f5 signal smacinit secondary 15 21 f5 initialize short multiply accumulate loop smacloop secondary 16 21 f6 short multiply accumulate loop smul secondary 14 21 f4 short multiply ssinc secondary 2e 22 fe store sixteen and increment statusclr secondary 27 22 f7 clear bits in status register statusset secondary 26 22 f6 set bits in status register statustst secondary 28 22 f8 test status register stl n primary d d n store local stnl n primary e e n store non-local stop secondary 34 23 f4 stop process sub secondary 05 f5 subtract subc secondary 11 21 f1 subtract with carry swap32 secondary 3e 23 fe byte swap 32 swinc secondary 30 23 f0 store word and increment timeslice secondary 0e fe timeslice umac secondary 13 21 f3 unsigned multiply accumulate unsign secondary 19 21 f9 unsign argument wait secondary 36 23 f6 wait wsub secondary 07 f7 word subscript xbword secondary 21 22 f1 sign extend byte to word xor secondary 20 22 f0 exclusive or xsword secondary 22 22 f2 sign extend sixteen to word
178/205 ? c compiling for the ST20-C1 c.1 generating prefix sequences prefixing is intended to be performed by a compiler or assembler. prefixing b y hand is not advised. normally a value can be loaded into the instruction data value by a variety of different prefix sequences . it is important to use the shortest possible sequence as this enhances both code compaction and execution speed. the best method of optimizing object code so as to minimize the number of prefix instructions needed is shown below. c.1.1 prefixing a constant the algorithm to generate a constant instruction data value e for a function op is described by the following recursive function. prefix( op , e ) = if (e < 16 and e 0) op( e ) else if (e 16) {prefix( pfix, e >> 4 ); op( e #f)} else if (e < 0) {prefix( nfix, (~e) >> 4 ); op( e #f)} where ( op, e ) is the instruction component with function code op and data field e , ~ is a bitwise not, and >> is a logical right shift. c.1.2 evaluating minimal symbol offsets several primary instructions have an operand that is an offset between the current value of the instruction pointer and some other part of the code. generating the optimal prefix sequence to create the instruction data value for one of these instruc- tions is more complicated. this is because two, or more, instructions with offset operands can interlock so that the minimal prefix sequences for each instruction is dependent on the prefixing sequences used for the others. for example consider the interlocking jumps below which can be prefixed in two distinct ways. the instructions j and cj are respectively jump and conditional jump . these are explained in more detail later. the sequence: cj +16; j -257 can be coded as pfix 1; cj 0; pfix 1; nfix 0; j 15 but this can be optimized to be cj 15; nfix 15; j 1 which is the encoding for the sequence cj +15; j -255
179/205 ? this is because when the two offsets are reduced, their prefixing sequences take 1 byte less so that the two interlocking jumps will still transfer control to the same instructions as before. this compaction of non-optimal prefix sequences is difficult to perform and a better method is to slowly build up the prefix sequences so that the optimal solution is achieved. the following algorithm performs this. 5 associate with each jump instruction or offset load an `estimate' of the number of bytes required to code it and initially set them all to 0. 6 evaluate all jump and load offsets under the current assumptions of the size of prefix sequences to the jumps and offset loads 7 for each jump or load offset set the number of bytes needed to the number in the shortest sequence that will build up the current offset. 8 if any change was made to the number of bytes required then go back to 2 oth- erwise the code has reached a stable state. the stable state that is achieved will be the optimal state. where the code being analyzed has alignment directives, then it is possible that this algorithm will not reach a stable state. one solution to this, is to allow the algorithm to increase the instruction size but not allow it to reduce the size. this is achieved by modifying stage 7 to choose the larger of: the currently calculated length, and the previously calculated length. this approach does not always lead to minimal sized code, but it guarantees termination of the algorithm. steps 2 and 3 can be combined so that the number of bytes required by each jump is updated as the offset is calculated. this does mean that if an estimate is increased then some previously calculated offsets may have been invalidated, but step 4 forces another loop to be performed when those offsets can be corrected. by initially setting the estimated size of offsets to zero, all jumps whose destination is the next instruction are optimized out. knowledge of the structure of code generated by the compiler allows this process to be performed on individual blocks of code rather than on the whole program. for example it is often possible to optimize the prefixing in the code for the sub-compo- nents of a programming language construct before the code for the construct is opti- mized. when optimizing the construct it is known that the sub-components are already optimal so they can each be considered as a fixed block of code which cannot be reduced. this algorithm may not be efficient for long sections of code whose underlying structure is not known. if no knowledge of the structure is available (e.g. in an assem- bler), all the code must be processed at once. in this case a code shrinking algorithm where in step one the initial number of bytes is set to twice the number of bytes per word is used. the prefix sequences then shr ink on each iteration of the loop. 1 or 2 iterations produce fairly good code although this method will not always produce optimal code as it will not correctly prefix the pathological example given above.
180/205 ? c.2 compiling switch statements the switch statement is a special form of conditional transfer where the transfer is determined by comparing an expression to a number of constants. when compiling the process switch x ... the expression x is evaluated and stored in a local variable by x; stl selector then each branch of the switch statement c 1 , ..., c n p can be compiled by ldl selector; ldc c 1 ; sub; cj l; ldl selector; ldc c 2 ; sub; cj l; ... ldl selector; eqc c n ;cjm; l: p; j end; m: where the label end: is placed at the end of the switch statement. c.2.3 optimal compilation of switch the compilation method given above will produce inefficient code for large switch statements. to produce more efficient code the following rules can be used. first build up a set of pairs of selector values and processes, consisting of every selector value in the switch statement along with its associated process e the process part of each pair can be represented by the offset to the start of the compiled code for that process. then the following rules can be used. 1 if there are 3 entries or less then use the method as described above. 2 if there are 12 entries or less then use a binary search to limit the number of comparisons required. 3 for more than 12 entries attempt to use a jump table. the offset of the start of each selected process is placed in the table against each selector value. entries that do not match a selector in the switch statement must contain the offset of an error handler process. this jump table should be the largest table such that about one third of the entries are filled. this compilation strategy is then recursively called to handle the two ends. the jab (section 4.10) and ldpi (section 4.5) instructions, can be used to jump to the selected piece of code. the choice of 3 or less entries, 12 or less entries and one third filled tab le are the values used in current st20 compilers.
181/205 ? consider compiling the following switch expression: switch x c 1 p 1 ... c n p n where, for brevity, it is assumed that all the switch selectors are already in increasing order. three entries or less this switch is compiled as: if (x = c 1 ) p 1 else if (x = c 2 ) p 2 ... else if (x = c n ) p n four to twelve entries this switch is compiled as: if (x <= c n/2 ) { if (x <= c n/4 ) ...etc. else ... etc. } else ... etc. using a jump table assume that c i ... c m form a third filled jump table. then the switch is compiled as: if ( x < c i ) { switch x c 1 p 1 ... c i-1 p i-1
182/205 ? } else if (x > c m ) ... similar else ... jump table code where jump table code is x; ldc c i ; sub; ldc jump_size; mul; ldc (jump_table-m); ldpi m: add; jab; jump_table: j case_0; j case_1; ... ; j case_k error: ... error code li: ... code for p i ... lm: ... code for p m the code at jump_table consists of a sequence of jump instructions which transfer control to the relevant branch li ... lm or to error . the destination, case_x ,of each of these jumps is lj if c j is equal to (c i + x) and is error otherwise. the code at error should be the same code as used at the end of an if statement where all the conditionals have been false . the add , ldpi and jab instructions are explained in other sections. all the jumps in the jump_table code must be encoded to the same length ( jump_size bytes) to enable them to be accessed as a byte array. nop , which is a two byte instruc- tion that performs no operation, can be used to ensure this where different operands require a different amount of prefixing. also note that in the special case where jump_size is 1, ` ldc jump_size ; mul ' can be removed from the sequence, and where jump_size is 4, ` ldc jump_size ; mul ' can be removed provided add is replaced with wsub . c.3 expression evaluation order let depth(e) be the number of stack locations needed for the evaluation of expression e , defined b y depth(constant) = 1 depth(variable) = 1 depth(function call) = `infinite' depth(e1 op e2) = if (depth(e1) > depth(e2)) depth(e1) else if (depth(e1) < depth(e2)) depth(e2) else depth(e1) + 1 that is, if the depth required for each expression is the same, then one extra stack location is required to store the result of the first expression, while the second expres- sion is being evaluated. if the stack requirements for each expression are different,
183/205 ? then the total stack requirement is the larger stack requirement of the individual expressions. this is only the case if care is taken over the order of evaluation. note that `infinite' should be taken as meaning greater than any finite depth - because a function call does not preserve values on the stack. let the function eval( e, r ) evaluate expression e where there are r registers available to perform the evaluation. where this expression is an operation on two sub expres- sions - e1 op e2 - it is efficiently evaluated by the following algorithm, where op commutes is true if aopb is equal to bopa and false otherwise: if (depth(e1) < r and depth(e2) < r) /* i.e. depth of both expressions is less than the number of registers available */ { if (depth(e2) > depth(e1)) { if (op commutes) { eval( e2, r ); eval( e1, r-1 ); op } else { eval( e2, r ); eval( e1, r-1 ); rev; op (*) } } else if (depth(e2) <= depth(e1)) { eval( e1, r ); eval( e2, r-1 ); op } } else if (depth(e1) >= r or depth(e2) >= r) { if (depth(e2) >= depth(e1)) { if (depth(e1) >= r ){ /* i.e. both depths >= r*/ eval( e2, r ); stl temp; eval( e1, r ); ldl temp; op } else { /* i.e. depth(e1) < r and depth(e2) >=r */ if (op commutes) { eval( e2, r ); eval( e1, r-1 ); op } else { /* i.e. operation doesn't commute */ eval( e2, r ); eval( e1, r-1 ); rev; op } } } else if (depth(e2) < depth(e1)) { if (depth(e2) >= r) { /* i.e. both depths >= r*/ if (op commutes){ eval( e1, r ); stl temp; eval( e2, r ); ldl temp; op } else { eval( e2, r ); stl temp; eval( e1, r ); ldl temp; op } } else { /* i.e. (depth(e2) < r) and depth(e1) >= r*/ eval( e1, r ); eval( e2, r-1 ); op
184/205 ? } } } the justification of this is as follows. if the depth of both expressions is less than the number of registers available ( r ), then there is no need to store the result of the first evaluation in a temporary variable. the deeper expression is evaluated first to ensure that the operation evaluates in the least number of stack registers. if this were not done then the total depth requirement would have to be incremented due to the extra location for storing the result of the first e valuation. if both expression depths are as great as r , then a local variable ( temp ) must be used to store the result of the first expression. it is again better to evaluate the expression with the larger depth if possible, because this minimizes the number of local variables required. if only one of the expressions is as great as r , then provided that expression is evaluated first, there is no need to store its result in a local variable. in the cases where a temporary variable temp is required to hold the value of the first expression in the evaluation of e1 op e2 , then that variable can be used as a temporary variable in the evaluation of the first e xpression. also a temporary variable used in the evaluation of the first expression and not used to hold its result can be used in the evaluation of second expression. the code sequence (e2; e1; rev; op) at (*) in the above algorithm, can be optimized further to (e1; e2; op) removing the execution of the rev instruction. but be aware that the latter uses an extra stack register, and so there is trade-off here between evaluation depth and code size. c.4 loading sequence the three registers of the evaluation stack are used to hold operands of instructions. evaluation of an operand or parameter may involve the use of more than one register. care is needed when evaluating such operands to ensure that the first oper and to be loaded is not pushed off the bottom of the evaluation stack by the evaluation of later operands. the processor does not detect evaluation stack overflow. three registers are available for loading the first operand, two registers for the second and one for the third. consequently, the instructions are designed so that creg holds the operand which, on average, is the most complex, and areg the operand which is the least complex. in some cases, it is necessar y to evaluate the areg and breg operands in advance, and to store the results in temporary variables. this can sometimes be avoided using the reverse instruction. any of the following sequences may be used to load the operands a , b and c into areg , breg and creg respectively.
185/205 ? 1c;b;a 2 c;a;b;rev 3 b; c; rev; a 4 a; c; rev; b; rev the choice of loading sequence, and of which operands should be evaluated in advance is determined by the number of registers required to evaluate each of the operands. in particular, if c requires more than two registers it must be loaded before a and b .if a or b requires more than two registers it must be evaluated before c and may need to be stored in a temporary variable if c requires more than two registers. table 8.1 gives the instruction sequences needed for loading three operands into the evaluation stack, where the number in the `load sequence' column refers to the list above. the columns labelled `temp' indicate where a local variable is needed to temporarily save an operand value in the load sequence. the variable `a' is used to store operand `a' and the variable `b' is used to store operand `b'. registers required temp load sequence instructions cbab a 2 1 1 1 c; b; a 1 2 2 c; a; b; rev 1 >2 4 a; c; rev; b; rev 21 1 c;b;a 2 2 * 1 a; stl a; c; b; ldl a 2 >2 * 1 a; stl a; c; b; ldl a >2 1 3 b; c; rev; a >2 2 * 3 a; stl a; b; c; rev; ldl a >2 >2 * 3 a; stl a; b; c; rev; ldl a >2 1 1 1 c;b;a 1 2 2 c; a; b; rev 1 >2 * 1 a; stl a; c; b; ldl a 21 1 c;b;a 2 2 * 1 a; stl a; c; b; ldl a 2 >2 * 1 a; stl a; c; b; ldl a >2 1 * 1 b; stl b; c; ldl b; a >2 2 * 2 b; stl b; c; a; ldl b; rev >2 >2 * * 1 a; stl a; b; stl b; c; ldl b; ldl a table 8.1 register loading sequences
186/205 ?
187/205 ? d glossary active process an active process in a multi-tasking program is one that is either executing or waiting for cpu time. it may have been interrupted or trapped or it may be waiting on a scheduling queue . address a 32-bit integer used to identify one byte of memory or memory-mapped device. st20 addresses are signed, i.e. the address range is the same as the range of a signed 32-bit integer. a pointer . address space the range of valid addresses. areg the 32-bit register at the top of the evaluation stack . arithmetic shift a shift in which the sign bit is preserved. an arithmetic right shift copies the sign bit into the vacated bits. array a data structure in which all the elements are of the same type and are identified by a non-negative integer subscript. a vector . bit a binary digit, which can take the value 1 (also called set or true) or 0 (also called clear or false). bitwise operation an operation on multi-bit values which treats each bit as a true (if set ) or false (if clear ). boolean logic values and calculations using and, or, and not. a multi-bit value is treated as boolean if it represents a single true of false value, as opposed to bitwise . breg the 32-bit register in the middle of the evaluation stack . byte an 8-bit value or location. cache fast memory used to temporarily hold copies of slow memory locations in order to provide high performance memory access with slow memory. channel a synchronous, one-way, point-to-point, unbuffered communications mechanism.
188/205 ? clear a bit is clear if it has the value 0. creg the 32-bit register at the bottom of the evaluation stack . current process the process being either being executed by the cpu, interrupted or trapped. dcu diagnostic controller unit . descriptor identifier of a process or exception . deschedule a process is descheduled when it is not being executed by the cpu and has not been interrupted or trapped by an exception handler but it is capable of being restarted. to deschedule a process is to make it descheduled. diagnostic controller unit st20 hardware macro-cell which provides fully non-intrusive breakpoints, watch- points and code tracing. dma direct memory access. a peripheral or external device performs dma when it reads directly from or writes directly to memory. dma peripheral a peripheral with a dma engine. double word a 64-bit value, occupying two words. evaluation stack the areg , breg and creg , which together behave as a stack. the evaluation stack is used for expression evaluation and to hold operands for instructions. the registers cannot be individually addressed, but values can be pushed onto the stack or popped off it. exception a mechanism for handling events outside the normal program flow. an exception may be an interrupt or a trap . exception handler the code and data which defines the action when an exception is taken. an exception handler may be a trap handler or an interrupt handler . exception level the signed integer specifying which exception will be taken, which is the word offset from the base of the exception vector table to the descriptor of the process or exception .
189/205 ? exception vector table the table mapping exception levels to user processes and exception descriptors . executing a process is executing if the cpu is currently modifying its state . only one process can be executing at any one time. external interrupt an interrupt generated by a peripheral or external device, routed through the interrupt controller and handled by an interrupt handler . function a named section of code which may have parameters and may return one or more values. function a primary instruction. function code the most significant 4-bits of an instruction component , which defines the action of the component. half-word a 16-bit value or location. half-word aligned an address is half-word aligned if it is divisible by two, i.e. if bit 0 is 0. idle the cpu is idle when there is no process or exception handler executing . inactive a process is inactive if it is capable of being restarted but it is currently waiting for some event to occur before it can continue. the event might be a semaphore signal or a peripheral completing a dma. instruction a code element corresponding to a single instruction set mnemonic, consisting of zero or more prefixes followed by a non-prefix instruction component . instruction component a single byte of code, consisting of a function code and 4 bits of data. instruction data value the operand of a primary instruction , which is built from the least significant 4 bits of each of the instruction components of the instruction. instruction pointer the 32-bit cpu register which holds the address of the next instruction to be executed by the current process . integer a whole number, which may be positive, negative or zero.
190/205 ? internal memory on-chip memory . interrupt a signal from outside the cpu to switch from normal execution to execution of an interrupt handler . if the interrupt causes a scheduling event, then that may cause an immediate trap . interrupt controller an on-chip peripheral which arbitrates between interrupt requests and signals to the cpu when an interrupt is required. interrupt handler the code and data which defines the action when an interrupt is taken. interrupt latency the time taken from receiving an interrupt signal to starting execution of the interrupt handler . interrupted a process is in an interrupted state if it is waiting for an interrupt handler to complete and it will continue as soon as the interrupt handler has completed. ioreg the input and output register, whose bits are directly connected to peripherals . iptr the instruction pointer . linked list a linked list is an ordered data structure where each element includes a pointer to the next element. a list is identified b y a front pointer, which points to the first element in the list. linked lists are also called queues . little-endian little-endian ordering of data, used by all st20s, means that less significant data is always held in lower addresses. this applies to bits in bytes, bytes in words and words in memory. list see linked list. local a local variable is one that is addressed by means of an offset from the workspace pointer. local variables are usually held on a stack and are defined within a function or procedure. cf. non-local . logical shift a shift in which the sign bit is shifted by the same amount as any other bit.
191/205 ? memory addressed devices which can be read and possibly written. reading read/write memory at a particular address gives the value that was last written to that address. reading read-only memory always gives the same value. memory-mapped addressed devices which are read and written as if they were memory , but do not necessarily return the last written value. microcode the on-chip hardware mechanism for implementing instructions. micro-kernel the st20 on-chip hardware support for multi-tasking. mostneg the most negative 32-bit integer, #80000000. the address of the base of memory. the value of the null process pointer notprocess . multi-tasking running several communicating processes on the same processor using time sharing. non-local a non-local variable is one that is addressed by means of an offset from the base address held in areg . non-local variables are usually not held on a stack and are defined globally. cf. local . notprocess the null process pointer, which has the value mostneg . on-chip emulator diagnostic controller unit . on-chip memory very fast memory included in the st20 chip. on-chip memory is usually located at the bottom of the address space . operate an instruction component, with function code #f and mnemonic opr , used to encode secondary instructions . the instruction data value identifies the secondar y instruction. operating system code controlling multi-tasking, interrupts and certain system operations, which may be called by a program. the st20 supports many of these facilities in micro- code without an operating system. operation a secondary instruction. peripheral a device connected to and controlled by the cpu.
192/205 ? pointer an address . prefix an instruction component used to extend the data value of the following instruction component. there are two prefixes - pfix (function code #2) which preserves the sign and nfix (function code #6) which complements the data value and so changes the sign. primary instruction one of thirteen directly coded instructions which therefore do not require an operate instruction component. a primary instruction has a data part associated with it, called the operand. cf. secondary instruction . priority a value associated with each process or interrupt which is used to make choices when conflicts occur . procedure a named section of code which may have parameters. process a sequential algorithm and data which can run in parallel with other processes.processes are also known as tasks or threads. each process is identi- fied b y a task descriptor which points to a process descriptor block. process descriptor block a data structure defining a process , including the saved instruction pointer , workspace pointer and a link used for queuein g processes. process pointer a pointer to a process . queue a linked list. real time operating system an operating system providing facilities for real-time programming, including multi- tasking and interrupt handling. register cache registers used to cache the lowest words of the work space in order to accelerate access to local variables. also called work space cache or register file . register file see register cache . rtos real-time operating system . scheduler code or hardware which controls how processes share cpu time.
193/205 ? scheduling kernel code to override the st20 built-in microcode scheduler , consisting mainly of trap handlers which are taken when a scheduling event occurs. scheduling queue the queue of processes waiting for cpu time. secondary instruction an instruction encoded using an operate instruction component. a secondary instruction has no data part associated with it, as the instruction data value is used to identify the instruction. cf. primary instruction . semaphore a mechanism for synchronizing and signalling between processes. set a bit is set when its value is 1. sign extension a signed value can be extended to occupy more bits by filling the most significant bits with copies of the sign bit. sign bit the most significant bit of a signed value , used to indicate the sign of the value. signed value value which could be positive or negative depending on the sign bit . sleep the cpu is asleep when its clocks are turned off to reduce power consumption. the cpu automatically goes to sleep after it becomes idle. it is woken by an external interrupt . slot a slot is a field of a data structure for holding a value. a slot normally occupies one word . stack a stack is a data storage structure that uses a `first in, last out' access model. adding an item to a stack is called pushing on, and extracting a value is called popping. a program stack is normally implemented using the wptr as the stack pointer. the areg , breg and creg form the evaluation stack . stack, evaluation see evaluation stack . state the state of a process is the data needed for the process to continue execution. this may include the evaluation stack, iptr , wptr , status register and local data. status register the status register holds cpu status information which must be saved if an interrupt occurs but is not saved if the process deschedules. some status register
194/205 ? bits are global and are preserved when a process is descheduled and others are local to a process and are lost when the process is descheduled . task a process . task descriptor the identifier of a process , which is a pointer to the process descriptor block . when a process is executing, the tdesc holds the task descriptor of the process. tdesc a 32-bit register which holds the task descriptor of the current process . thread a dynamically generated process . timeslice deschedule a process to allow other processes access to the cpu. timeslicing prevents any one process from occupying too much cpu time. a timesliced process is normally added to the back of the scheduling queue and the process on the front of the queue is restarted. trap an exception caused by software, or an interrupt initiating a scheduling event. trap handler the code and data which define what happens when a trap is taken. trapped a process is trapped when it is waiting for a trap handler to complete. unsigned value value which could only be positive, so the most significant bit is not used as a sign bit . vector an array . waiting a process is waiting for an event if it cannot continue execution until that event has occurred. the event could be for example a communication or a semaphor e signal. word a word is a four byte (32-bit) location for data. word-aligned an address is word-aligned if it is divisible by 4, i.e. if the least significant two bits are zero. work space space in memory for local variables and values.
195/205 ? work space cache registers used to cache the lowest words of the work space in order to accelerate access to local variables. also called register cache or register file workspace pointer a 32-bit register pointing to the work space for the current process . wptr the workspace pointer.
196/205 ?
197/205 index ? index symbols + (plus) , 11 .. (ellipsis) , 9 / (divide) , 11 < (less than) , 11 = (equals) , 11 > (greater than) , 11 >> (logical shift right) , 11 @ (word offset) , 10 { } (braces) , 13 (prime) , 10 (less than or equal to) , 11 (greater than or equal to) , 11 (is not equal to) , 11 numerics 16-bit , 32 assignment , 35 load , 31 , 124 signed , 31 , 125 multiply , 146 multiply accumulate , 56 , 143 , 144 sign extension , 40 , 167 store , 31 , 147 a active , 78 , 187 adc , 36 , 88 add , 36 , 89 constant , 36 , 88 with carry , 38 , 90 addc , 38 , 90 address , 187 calculation , 10 , 41 43 load local , 41 load non-local , 41 space , 18 , 187 subscript , 41 addressing , 16 adjust work space , 91 ajw , 48 , 91 alignment , 18 and bitwise , 11 , 47 boolean , 11 , 46 instruction , 92 anti-rotate stack , 30 , 93 architecture , 16 28 areg , 20 , 21 , 30 , 187 arithmetic , 35 40 add , 89 boolean , 45 47 divide , 102 modulo , 11 multiply accumulate , 56 67 saturated , 138 shift , 187 shift right , 94 subtract , 155 subtract with carry , 156 unchecked , 11 unsign , 162 arot , 30 , 93 arrays , 41 , 187 word subscript , 164 ashr , 48 , 94 assignment byte , 35 single word , 35 b biquad , 56 , 58 , 95 bit , 187 load , 47 , 96 mask , 47 read modify write , 47 , 135 store , 47 , 98 bitld , 47 , 96 bitmask , 47 , 52 , 97 bitsperword , 172 bitst , 47 , 98 bitwise , 187 and , 11 exclusive or , 166 not , 11 , 130 operations , 47 or , 11 , 131 xor , 11 block copy , 31 , 33 load , 126 store , 158 boolean , 187 expressions , 45 47 branch , 43 , 100 breakpoint , 71 , 99 trap , 71 breg , 20 , 21 , 30 , 187 buffer size multiply accumulate , 57 byte , 32 , 187 addressing , 19
index 198/205 ? arrays , 43 assignment , 35 load , 31 load and increment , 115 ordering compatibility , 17 selector , 18 sign extension , 40 , 165 store , 31 , 139 swap , 48 , 157 bytesperword , 172 c cache , 187 call exception , 104 function , 48 52 , 108 procedure , 48 52 carry , 22 , 38 channel , 187 channel-type peripherals , 53 checked arithmetic , 36 cj , 43 , 100 clear , 188 status bit , 55 status bits , 148 clock timeslicing , 81 code in instruction descriptions , 6 coding of instruction , 6 , 24 comments in instruction descriptions , 8 , 9 comparison , 43 45 equals constant , 43 , 106 greater than , 43 , 110 unsigned , 43 , 111 order , 132 unsigned , 133 compatibility byte ordering , 17 complement , 47 conditional jump , 43 , 100 conditionals , 43 45 conditions in instruction descriptions , 13 constants , 172 equals , 43 loading , 31 , 116 from table , 34 machine constant definitions , 14 , 169 used in instruction descriptions , 14 , 172 control block exception , 73 process queue , 80 conversion object length , 17 , 40 type , 12 create bit mask , 97 creg , 20 , 21 , 30 , 188 current process , 188 d data format multiply accumulate , 58 , 65 data structures , 171 data types , 9 dcu , 188 decrement , 36 , 88 definition in instruction descriptions , 7 , 8 depth of stack needed , 182 dequeue a process , 79 , 101 descheduled process , 79 , 188 state , 80 , 82 description in instruction descriptions , 7 descriptor , 188 in exception vector table , 72 of process , 79 task , 24 diagnostic controller unit , 188 direct memory access , 53 disabling exceptions , 77 timeslicing , 81 division , 36 , 102 divstep , 36 , 102 dma , 188 peripherals , 53 double word , 19 , 188 arithmetic , 38 multiply , 39 dsp , 56 67 dup , 30 , 103 duplicate top of stack , 30 , 103 dynamic allocation of workspace , 52 e ecall , 71 , 104 ellipsis , 9 else , 13 emulator , 191 enabling exceptions , 77 timeslicing , 81 encoding of instructions , 6 , 24
199/205 index ? enqueue a process , 79 , 105 eqc , 43 , 106 equals constant , 43 , 106 eret , 71 , 107 error signals in instruction descriptions , 8 evaluation arithmetic , 35 40 boolean , 45 47 function , 51 of addresses , 41 43 of expressions , 33 35 , 182 185 stack , 19 , 21 , 30 , 33 35 , 182 185 , 188 loading sequences , 34 subscripts , 42 exception , 70 77 , 188 call , 104 control block , 73 handler , 188 initial state , 74 levels , 71 , 170 , 188 return , 107 type , 72 vector table , 72 , 189 exceptionbase , 72 , 172 exceptionprocesstype , 73 , 172 exclusive or , 166 bitwise , 47 executing , 78 , 189 expression depth , 182 184 evaluation , 33 35 , 182 185 using functions , 51 extend sign , 40 , 165 external interrupt , 189 f false , 16 , 43 , 172 fcall , 48 , 108 filter biquad iir , 58 iir step , 95 function , 189 call , 48 52 , 108 code , 7 , 25 , 189 evaluation , 51 functions in instruction descriptions , 12 g gajw , 48 , 109 general adjust workspace , 109 global_interrupt_enable , 22 , 77 greater than , 43 , 110 unsigned , 43 , 111 gt , 43 , 110 gtu , 43 , 111 h half-word , 16 , 32 , 189 aligned , 19 , 189 assignment , 35 load , 31 , 124 signed , 31 , 125 multiply , 36 , 146 multiply accumulate , 56 , 143 , 144 sign extension , 40 , 167 store , 31 , 147 high_word , 12 highestexception , 172 i i/o , 52 55 identity of device , 14 , 122 idle , 85 , 189 trap , 72 if compiling , 43 45 in definitions , 13 iir filter , 58 , 95 inactive , 78 , 82 , 189 process restarting , 82 increment , 36 , 88 indirection of exceptions , 72 initializing exception handlers , 76 multi-tasking , 83 smacloop , 143 input/output , 52 55 , 112 instruction , 14 , 189 address , 41 component , 25 , 189 data value , 25 , 189 definitions , 87 encoding , 6 , 24 pointer , 20 , 189 load , 41 , 121 int16 , 12 integer , 189 length conversion , 40 internal memory , 190 interrupt , 70 77 , 190 controller , 190 enable , 22 handler , 190
index 200/205 ? latency , 190 interrupt_mode , 22 , 23 interrupted , 78 , 190 io , 52 , 112 ioreg , 20 , 24 , 52 , 190 iptr , 20 , 190 load , 41 j j , 43 , 113 jab , 43 , 48 , 114 jump , 43 45 , 112 , 113 absolute , 43 , 114 conditional , 43 , 100 table , 181 l lbinc , 31 , 115 ldc , 31 , 116 ldl , 31 , 117 ldlp , 41 , 118 ldnl , 31 , 119 ldnlp , 41 , 120 ldpi , 41 , 121 ldprodid , 14 , 122 ldtdesc , 52 , 79 , 123 length conversion , 17 link in queue , 80 linked list , 80 , 190 list , 190 little-endian , 16 , 19 , 157 , 190 load , 31 33 bit , 47 , 96 byte , 31 , 115 constant , 31 , 116 instruction pointer , 41 local , 31 , 117 local pointer , 41 , 118 non-local , 31 , 119 non-local pointer , 41 , 120 operands , 34 parameters , 50 pointer to instruction , 121 product identity , 122 sequence integer stack , 34 sequences , 184 sixteen bit , 31 , 124 signed , 125 sixteen bit signed , 125 task descriptor , 123 word , 31 , 126 local , 19 , 23 , 31 , 190 load pointer , 118 load variable , 31 , 117 store variable , 31 , 151 local_interrupt_enable , 22 , 77 logic , 45 47 bitwise instructions , 47 logical shift , 190 long arithmetic , 38 multiplication , 127 subtract , 156 longmode , 58 , 172 low_word , 12 lowestexception , 172 lsinc , 31 , 124 lsxinc , 31 , 125 lwinc , 31 , 126 m mac , 56 , 127 mac_buffer , 22 , 57 mac_count , 22 , 57 mac_mode , 22 , 57 mac_scale , 22 , 57 mask , 47 create , 97 maximum , 45 , 132 unsigned , 133 maxtimeslicecount , 81 , 172 memory , 18 , 191 block copy , 33 mapped , 191 mapped peripherals , 53 read modify write , 47 , 135 representation of , 10 microcode , 191 micro-kernel , 191 minimum , 45 , 132 unsigned , 133 minus , 36 , 38 modulo arithmetic , 11 mostneg , 16 , 172 , 191 mostpos , 16 , 172 move , 33 mul , 36 , 128 multiply , 36 , 128 half-word , 36 multiple length , 39 multiply accumulate , 56 67 , 127 short loop , 144 initialize , 143 unsigned , 38 , 161 multi-tasking , 78 85 , 191
201/205 index ? n negation , 38 next instruction , 9 nfix , 25 no operation , 129 non-local , 31 , 191 load pointer , 120 load variable , 31 , 119 store variable , 152 nop , 129 not bitwise , 47 boolean , 11 , 46 instruction , 130 notation , 6 14 notprocess , 18 , 172 , 191 o object length conversion , 40 objects , 9 on-chip emulator , 191 on-chip memory , 191 operands in descriptions , 6 primary instructions , 26 secondary instructions , 34 operate , 25 , 191 operating system , 191 operation , 191 code , 6 , 25 , 27 operations bitwise , 47 operators in instruction definitions , 11 in instruction descriptions , 11 opr , 8 , 27 or bitwise , 11 , 47 boolean , 11 , 46 instruction , 131 order , 43 of loads , 184 unsigned , 43 order , 132 ordering of data , 16 values , 43 45 orderu , 133 output , 52 55 , 112 overflow , 22 , 36 , 37 saturate , 138 p parallel programming , 78 85 parameters procedure , 50 peripherals , 52 55 , 191 pfix , 25 plus , 36 pointer , 192 load local , 41 load non-local , 41 reserved values , 18 pop , 21 prefixing , 25 , 178 , 192 primary instructions , 8 , 25 , 26 , 192 prime notation in instruction descriptions , 10 priority , 78 , 170 , 192 procedure , 192 call , 48 52 process , 78 85 , 192 creation , 83 current , 188 dequeue , 101 descriptor , 24 , 170 descriptor block , 79 , 192 enqueue , 105 pointer , 192 queues , 80 run , 137 state , 9 , 24 , 79 in descriptions , 7 states , 78 stop , 153 timeslice , 159 transitions , 78 user , 22 waiting , 80 product identity , 14 , 122 productid , 172 push , 21 pw.iptr , 82 pw.wptr , 82 q q.bptrloc , 80 , 171 q.fptrloc , 80 , 171 q15 , 58 q31 , 58 , 65 queue , 192 control block , 80 scheduling , 80
index 202/205 ? r read modify write , 47 , 135 real time operating system , 192 register , 20 cache , 20 , 192 file , 192 in instruction descriptions , 7 memory mapped , 53 rem , 11 remainder , 36 repeat loop , 45 representing memory in instruction descriptions , 10 rescheduling a process , 82 reserved memory , 18 return exception , 107 from procedure , 49 rev , 30 , 134 reverse stack , 30 , 134 rmw , 47 , 135 rot , 30 , 136 rotate stack , 30 , 136 rtos , 192 run , 79 , 82 , 84 , 137 trap , 72 s s.back , 79 , 84 , 171 s.count , 84 , 171 s.front , 84 , 171 saturate , 37 , 138 savedtaskdescriptor , 172 sbinc , 31 , 139 scaling multiply accumulate , 59 scheduler , 192 schedulerqptr , 80 , 172 scheduling , 78 85 kernel , 193 kernels , 84 queue , 80 , 193 secondary instructions , 8 , 25 , 27 , 193 semaphore , 84 85 , 193 signal (v) , 84 , 85 , 142 wait (p) , 85 , 163 set , 193 status bits , 55 , 149 setting up exception handler , 76 multi-tasking , 83 process , 83 semaphore , 84 shift , 48 instructions , 47 logical left , 140 right arithmetic , 94 right logical , 141 shl , 48 , 140 short multiply , 36 , 146 multiply accumulate loop , 144 store , 147 shortmode , 58 , 172 shr , 48 , 141 sign bit , 193 extension , 17 , 40 , 193 byte , 165 half-word , 31 , 167 signal , 84 , 142 signal processing , 56 67 signed arithmetic , 17 shift right , 48 value , 193 sixteen bit , 16 , 32 assignment , 35 load , 31 , 124 signed , 31 , 125 multiply , 36 , 146 multiply accumulate , 56 , 143 , 144 sign extension , 40 , 167 store , 31 , 147 sleep , 22 , 23 , 85 , 193 slot , 16 , 193 smacinit , 56 , 57 , 143 smacloop , 56 , 144 initialize , 143 smul , 36 , 146 ssinc , 31 , 147 stack , 193 anti-rotate , 30 duplicate , 30 , 103 evaluation , 19 , 21 , 193 memory , 19 reverse , 30 , 134 rotate , 30 , 136 start_next_task , 22 , 23 state , 193 status register , 8 , 20 , 21 , 55 , 170 , 193 clear bits , 148 exception handler start state , 74 restart value , 83 restarted process state , 83 set bits , 149 test , 150 statusclr , 55 , 148
203/205 index ? statusset , 55 , 149 statustst , 55 , 150 steps multiply accumulate , 57 stl , 31 , 151 stnl , 31 , 152 stop , 52 , 79 , 84 , 153 trap , 72 store , 31 33 bit , 47 , 98 byte , 31 , 139 local , 31 , 151 non-local , 31 , 152 sixteen bit , 31 word , 31 , 158 sub , 36 , 155 subc , 38 , 156 subprogram call , 48 52 subscript , 42 address , 41 evaluation , 42 in instruction definitions , 9 word , 164 subtract , 36 , 155 with carry , 38 , 156 swap bytes , 48 , 157 swap32 , 17 , 48 , 157 swinc , 31 , 158 switch statements , 180 system traps , 71 , 84 t table of constants loading from , 34 task , 78 , 194 descriptor , 79 , 194 load , 123 tdesc , 20 , 24 , 194 test status bit , 55 , 150 threads , 78 , 194 timeslice , 45 , 79 , 81 , 159 , 194 trap , 72 timeslice_count , 22 , 81 timeslice_enable , 22 , 81 trap_mode , 22 , 23 trapped , 78 , 194 traps , 70 77 , 194 handlers , 194 true , 16 , 43 , 172 type conversion , 12 of data , 9 of exception , 72 u umac , 38 , 56 , 161 unary minus , 38 unchecked arithmetic , 11 undefined , 9 underflow , 22 , 36 , 37 saturate , 138 unsign , 36 , 162 unsigned , 10 greater than , 43 , 111 multiply accumulate , 38 , 161 order , 133 value , 194 user process , 22 user_mode , 22 userprocesstype , 73 , 172 v values , 16 variable address , 41 allocating work space for , 49 assignment , 35 vector , 194 exception table , 72 w wait , 84 , 163 waiting process , 79 , 80 , 194 while loop , 45 word , 16 , 194 address , 18 aligned , 18 , 194 arrays , 43 assignment , 35 load , 126 multiply accumulate , 56 store , 158 subscript , 41 , 164 work space , 19 , 23 , 170 , 194 address , 23 adjust , 49 , 91 cache , 20 , 195 dynamic allocation , 52 general adjust , 109 pointer , 19 , 23 , 195 wptr , 19 , 20 , 23 , 195 wsub , 41 , 164 x x (multiply) , 11 xbword , 40 , 165 xor
index 204/205 ? bitwise , 11 , 47 , 166 xsword , 40 , 167
information furnished is believed to be accurate and reliable. however, sgs-thomson microelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. no license is granted by implication or otherwise under any patent or patent rights of sgs-thomson microelectronics. specifications mentioned in this pub lication are subject to change without notice. this publication supersedes and replaces all information previously supplied. sgs-thomson microelectronics products are not authorized for use as critical components in life support devices or systems without express written approval of sgs-thomson microelectronics. ? 1997 sgs-thomson microelectronics - all rights reserved ims and ds-link ? are trademarks of sgs-thomson microelectronics limited. is a registered trademark of the sgs-thomson microelectronics group. 205/205 ? ? document number: 72-trn-274-01


▲Up To Search▲   

 
Price & Availability of ST20-C1

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X